Sort GET /staff output by the time each grant was created

This commit is contained in:
Colin McDonald 2016-08-18 14:26:36 -04:00
parent 95944d023d
commit 287e6b744a

View File

@ -21,7 +21,7 @@ public final class GETStaff implements Handler<RoutingContext> {
} }
}); });
Map<String, Set<User>> result = new TreeMap<>((a, b) -> { Map<String, List<User>> result = new TreeMap<>((a, b) -> {
Rank aRank = staffRanks.get(a); Rank aRank = staffRanks.get(a);
Rank bRank = staffRanks.get(b); Rank bRank = staffRanks.get(b);
@ -29,6 +29,7 @@ public final class GETStaff implements Handler<RoutingContext> {
}); });
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v)); List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));
staffGrants.sort((a, b) -> a.getAddedAt().compareTo(b.getAddedAt()));
for (Grant staffGrant : staffGrants) { for (Grant staffGrant : staffGrants) {
if (staffGrant.isActive()) { if (staffGrant.isActive()) {
@ -36,7 +37,7 @@ public final class GETStaff implements Handler<RoutingContext> {
Rank rank = staffRanks.get(staffGrant.getRank()); Rank rank = staffRanks.get(staffGrant.getRank());
if (!result.containsKey(rank.getId())) { if (!result.containsKey(rank.getId())) {
result.put(rank.getId(), new HashSet<>()); result.put(rank.getId(), new ArrayList<>());
} }
result.get(rank.getId()).add(user); result.get(rank.getId()).add(user);