Update /staff for Ariel (new schhema)

This commit is contained in:
Colin McDonald 2016-08-02 19:16:21 -04:00
parent 7f10888151
commit 23a6739eb1

View File

@ -12,38 +12,38 @@ import java.util.*;
public final class GETStaff implements Handler<RoutingContext> { public final class GETStaff implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
Map<String, Rank> staffRanks = new HashMap<>(); Map<String, Rank> staffRanks = new HashMap<>();
Rank.findAll().forEach(rank -> { Rank.findAll().forEach(rank -> {
if (rank.isStaffRank()) { if (rank.isStaffRank()) {
staffRanks.put(rank.getId(), rank); staffRanks.put(rank.getId(), rank);
} }
}); });
Map<String, Set<User>> result = new TreeMap<>((first, second) -> { Map<String, Set<User>> result = new TreeMap<>((a, b) -> {
Rank firstRank = staffRanks.get(first); Rank aRank = staffRanks.get(a);
Rank secondRank = staffRanks.get(second); Rank bRank = staffRanks.get(b);
return Integer.compare(firstRank.getGeneralWeight(), secondRank.getGeneralWeight()); return Integer.compare(bRank.getGeneralWeight(), aRank.getGeneralWeight());
}); });
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v)); List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));
for (Grant staffGrant : staffGrants) { for (Grant staffGrant : staffGrants) {
if (staffGrant.isActive()) { if (staffGrant.isActive()) {
User user = SyncUtils.runBlocking(v -> User.findById(staffGrant.getId(), v)); User user = SyncUtils.runBlocking(v -> User.findById(staffGrant.getUser(), v));
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 HashSet<>());
} }
result.get(rank.getId()).add(user); result.get(rank.getId()).add(user);
} }
} }
APIv3.respondJson(ctx, 200, result); APIv3.respondJson(ctx, 200, result);
} }
} }