Commit ?active=true flag for GET /punishments

This commit is contained in:
Colin McDonald 2016-07-09 17:21:43 -04:00
parent 97b296a79d
commit d519527986

View File

@ -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<RoutingContext> {
public void handle(RoutingContext ctx) {
@ -14,11 +16,16 @@ public final class GETPunishments implements Handler<RoutingContext> {
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) {