Added getting sorted students
This commit is contained in:
@ -5,13 +5,15 @@ 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 of Assignment which can save assignments, diplay assignments, get
|
||||
* ammount of assigments.
|
||||
*/
|
||||
|
||||
@Service
|
||||
@ -19,11 +21,15 @@ 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
|
||||
*/
|
||||
@ -32,16 +38,14 @@ public class AssignmentService {
|
||||
}
|
||||
|
||||
/*
|
||||
* getCommisionAssignments
|
||||
* Return id of the commision
|
||||
* getCommisionAssignments Return id of the commision
|
||||
*/
|
||||
public List<Assignment> getCommisionAssignments(Commision com) {
|
||||
return this.repo.getByCommision(com.getId());
|
||||
}
|
||||
|
||||
/*
|
||||
* getAssignmentsAmmount
|
||||
* Return count assignments ammount
|
||||
* getAssignmentsAmmount Return count assignments ammount
|
||||
*/
|
||||
public long getAssignmentsAmmount() {
|
||||
return this.repo.count();
|
||||
@ -49,10 +53,19 @@ public class AssignmentService {
|
||||
|
||||
/**
|
||||
* 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());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.plannaplan.services;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
@ -153,4 +154,15 @@ public class UserService {
|
||||
return this.repo.getAllByRole(UserRoles.ADMIN).size() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* get students sorted by their ranking
|
||||
*
|
||||
* @return list of students
|
||||
*/
|
||||
public List<User> getStudentsSortedByRanking() {
|
||||
return this.repo.getAllByRole(UserRoles.STUDENT).stream().sorted((u1, u2) -> {
|
||||
return -1 * u1.getRanking().compareTo(u2.getRanking());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user