72 lines
1.7 KiB
Java
Executable File
72 lines
1.7 KiB
Java
Executable File
package com.plannaplan.services;
|
|
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import com.plannaplan.entities.Assignment;
|
|
import com.plannaplan.entities.Commision;
|
|
import com.plannaplan.entities.User;
|
|
import com.plannaplan.repositories.AssignmentRepository;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
/**
|
|
* Service of Assignment which can save assignments, diplay assignments, get
|
|
* ammount of assigments.
|
|
*/
|
|
|
|
@Service
|
|
public class AssignmentService {
|
|
@Autowired
|
|
private AssignmentRepository repo;
|
|
|
|
@Autowired
|
|
private UserService userService;
|
|
|
|
public AssignmentService() {
|
|
}
|
|
|
|
/**
|
|
* Save given assignment
|
|
*
|
|
* @param assignment assignment to save
|
|
* @return assignment saved assignment with database id
|
|
*/
|
|
public Assignment save(Assignment assignment) {
|
|
return this.repo.save(assignment);
|
|
}
|
|
|
|
/*
|
|
* getCommisionAssignments Return id of the commision
|
|
*/
|
|
public List<Assignment> getCommisionAssignments(Commision com) {
|
|
return this.repo.getByCommision(com.getId());
|
|
}
|
|
|
|
/*
|
|
* getAssignmentsAmmount Return count assignments ammount
|
|
*/
|
|
public long getAssignmentsAmmount() {
|
|
return this.repo.count();
|
|
}
|
|
|
|
/**
|
|
* Get assigmnent by id
|
|
*
|
|
* @param id id of assigmnent
|
|
* @return Optional of assignment
|
|
*/
|
|
public Optional<Assignment> getById(Long id) {
|
|
return this.repo.findById(id);
|
|
}
|
|
|
|
public void callAcceptAlgorythm() {
|
|
final List<User> students = this.userService.getStudentsSortedByRanking();
|
|
|
|
students.forEach(e -> {
|
|
System.out.println(e.getRanking());
|
|
});
|
|
}
|
|
}
|