Added getting sorted students

This commit is contained in:
Filip Izydorczyk
2021-01-02 14:35:00 +01:00
parent ff9aa64470
commit 4b096a50bf
4 changed files with 52 additions and 7 deletions

View File

@ -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());
}
}