From e14ea127cb15ec594101b2a9969f9cfe7f829544 Mon Sep 17 00:00:00 2001 From: Francisco Saldanha Date: Thu, 20 Oct 2016 21:40:55 -0200 Subject: [PATCH] Add the ability to specify the punisher as a parameter in the GET punishments route --- src/main/java/net/frozenorb/apiv3/model/Punishment.java | 6 +++++- .../frozenorb/apiv3/route/punishments/GETPunishments.java | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/model/Punishment.java b/src/main/java/net/frozenorb/apiv3/model/Punishment.java index 7737dd0..ff46f9c 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Punishment.java +++ b/src/main/java/net/frozenorb/apiv3/model/Punishment.java @@ -48,7 +48,11 @@ public final class Punishment { punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); } - public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback> callback) { + public static void findPaginated(Document query, int skip, int pageSize, UUID addedBy, SingleResultCallback> callback) { + if (addedBy != null) { + query.put("addedBy", addedBy); + } + punishmentsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback)); } diff --git a/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java b/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java index 68d28e6..fa3e357 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java @@ -8,6 +8,7 @@ import net.frozenorb.apiv3.util.ErrorUtils; import net.frozenorb.apiv3.util.UuidUtils; import org.bson.Document; +import java.util.UUID; import java.util.stream.Collectors; public final class GETPunishments implements Handler { @@ -16,8 +17,9 @@ public final class GETPunishments implements Handler { try { int skip = ctx.request().getParam("skip") == null ? 0 : Integer.parseInt(ctx.request().getParam("skip")); int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize")); + UUID addedBy = ctx.request().getParam("addedBy") == null ? null : UUID.fromString(ctx.request().getParam("addedBy")); - Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, (punishments, error) -> { + Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", UuidUtils.parseUuid(ctx.request().getParam("user"))), skip, pageSize, addedBy, (punishments, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else {