From d5195279861158570a018a3e72a7af233e8fb5d1 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sat, 9 Jul 2016 17:21:43 -0400 Subject: [PATCH] Commit ?active=true flag for GET /punishments --- .../apiv3/route/punishments/GETPunishments.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 27d8947..f2f8a32 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java @@ -7,6 +7,8 @@ import net.frozenorb.apiv3.model.Punishment; import net.frozenorb.apiv3.util.ErrorUtils; import org.bson.Document; +import java.util.stream.Collectors; + public final class GETPunishments implements Handler { public void handle(RoutingContext ctx) { @@ -14,11 +16,16 @@ public final class GETPunishments implements Handler { 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")); - Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> { + Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (punishments, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else { - APIv3.respondJson(ctx, 200, grants); + if (ctx.request().getParam("active") != null) { + boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active")); + APIv3.respondJson(ctx, 200, punishments.stream().filter(punishment -> punishment.isActive() == requireActive).collect(Collectors.toList())); + } else { + APIv3.respondJson(ctx, 200, punishments); + } } }); } catch (NumberFormatException ignored) {