Merge pull request #57 from FrozenOrb/specify-punisher

Add the ability to specify the punisher as a parameter in the GET pun…
This commit is contained in:
Jonathan Halterman 2016-10-20 17:01:56 -07:00 committed by GitHub
commit 1b343f98f7
2 changed files with 8 additions and 2 deletions

View File

@ -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<List<Punishment>> callback) {
public static void findPaginated(Document query, int skip, int pageSize, UUID addedBy, SingleResultCallback<List<Punishment>> 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));
}

View File

@ -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<RoutingContext> {
@ -16,8 +17,9 @@ public final class GETPunishments implements Handler<RoutingContext> {
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 {