diff --git a/src/main/java/net/frozenorb/apiv3/model/Grant.java b/src/main/java/net/frozenorb/apiv3/model/Grant.java index bef6794..86637b4 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Grant.java +++ b/src/main/java/net/frozenorb/apiv3/model/Grant.java @@ -38,8 +38,8 @@ public final class Grant { @Getter private Instant removedAt; @Getter private String removalReason; - public static List findAllSync() { - return SyncUtils.blockMulti(grantsCollection.find().sort(new Document("addedAt", -1))); + public static void findAll(SingleResultCallback> callback) { + grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), callback); } public static List findByRankSync(Collection ranks) { @@ -59,8 +59,8 @@ public final class Grant { return SyncUtils.blockMulti(grantsCollection.find(new Document("user", user))); } - public static void findAllPaginated(int skip, int pageSize, SingleResultCallback> callback) { - grantsCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback); + public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback> callback) { + grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback); } public static void findById(String id, SingleResultCallback callback) { @@ -72,18 +72,18 @@ public final class Grant { } public static void findByUser(UUID user, SingleResultCallback> callback) { - grantsCollection.find(new Document("user", user)).into(new ArrayList<>(), callback); + grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), callback); } public static void findByUserGrouped(Iterable users, SingleResultCallback>> callback) { - grantsCollection.find(new Document("user", new Document("$in", users))).into(new ArrayList<>(), (grants, error) -> { + grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), (grants, error) -> { if (error != null) { callback.onResult(null, error); } else { Map> result = new HashMap<>(); for (UUID user : users) { - result.put(user, new ArrayList<>()); + result.put(user, new LinkedList<>()); } for (Grant grant : grants) { diff --git a/src/main/java/net/frozenorb/apiv3/model/IpBan.java b/src/main/java/net/frozenorb/apiv3/model/IpBan.java index 5a44a43..f9ebde6 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpBan.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpBan.java @@ -43,8 +43,8 @@ public final class IpBan { return SyncUtils.blockOne(ipBansCollection.find(new Document("_id", id))); } - public static void findAllPaginated(int skip, int pageSize, SingleResultCallback> callback) { - ipBansCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback); + public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback> callback) { + ipBansCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback); } public static void findById(String id, SingleResultCallback callback) { @@ -52,18 +52,18 @@ public final class IpBan { } public static void findByIp(String userIp, SingleResultCallback> callback) { - ipBansCollection.find(new Document("userIp", userIp)).into(new ArrayList<>(), callback); + ipBansCollection.find(new Document("userIp", userIp)).into(new LinkedList<>(), callback); } public static void findByIpGrouped(Iterable userIps, SingleResultCallback>> callback) { - ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new ArrayList<>(), (ipBans, error) -> { + ipBansCollection.find(new Document("userIp", new Document("$in", userIps))).into(new LinkedList<>(), (ipBans, error) -> { if (error != null) { callback.onResult(null, error); } else { Map> result = new HashMap<>(); for (String userIp : userIps) { - result.put(userIp, new ArrayList<>()); + result.put(userIp, new LinkedList<>()); } for (IpBan ipBan : ipBans) { diff --git a/src/main/java/net/frozenorb/apiv3/model/Punishment.java b/src/main/java/net/frozenorb/apiv3/model/Punishment.java index e6f15f7..9a5a41c 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Punishment.java +++ b/src/main/java/net/frozenorb/apiv3/model/Punishment.java @@ -43,9 +43,9 @@ public final class Punishment { @Getter private Instant removedAt; @Getter private String removalReason; - public static List findByTypeSync(Collection types) { + public static void findByType(Collection types, SingleResultCallback> callback) { Collection convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList()); - return SyncUtils.blockMulti(punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes)))); + punishmentsCollection.find(new Document("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), callback); } public static Punishment findByIdSync(String id) { @@ -69,8 +69,8 @@ public final class Punishment { return SyncUtils.blockMulti(punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes)))); } - public static void findAllPaginated(int skip, int pageSize, SingleResultCallback> callback) { - punishmentsCollection.find().sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new ArrayList<>(), callback); + public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback> callback) { + punishmentsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback); } public static void findById(String id, SingleResultCallback callback) { @@ -86,18 +86,18 @@ public final class Punishment { } public static void findByUser(UUID user, SingleResultCallback> callback) { - punishmentsCollection.find(new Document("user", user)).into(new ArrayList<>(), callback); + punishmentsCollection.find(new Document("user", user)).into(new LinkedList<>(), callback); } public static void findByUserGrouped(Iterable users, SingleResultCallback>> callback) { - punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new ArrayList<>(), (punishments, error) -> { + punishmentsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), (punishments, error) -> { if (error != null) { callback.onResult(null, error); } else { Map> result = new HashMap<>(); for (UUID user : users) { - result.put(user, new ArrayList<>()); + result.put(user, new LinkedList<>()); } for (Punishment punishment : punishments) { @@ -115,7 +115,7 @@ public final class Punishment { public static void findByUserAndType(UUID user, Collection types, SingleResultCallback> callback) { Collection convertedTypes = types.stream().map(PunishmentType::name).collect(Collectors.toList()); - punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new ArrayList<>(), callback); + punishmentsCollection.find(new Document("user", user).append("type", new Document("$in", convertedTypes))).into(new LinkedList<>(), callback); } public Punishment() {} // For Jackson diff --git a/src/main/java/net/frozenorb/apiv3/route/auditLog/GETAuditLog.java b/src/main/java/net/frozenorb/apiv3/route/auditLog/GETAuditLog.java index f2828ce..5f88d6f 100644 --- a/src/main/java/net/frozenorb/apiv3/route/auditLog/GETAuditLog.java +++ b/src/main/java/net/frozenorb/apiv3/route/auditLog/GETAuditLog.java @@ -14,7 +14,8 @@ public final class GETAuditLog 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")); - AuditLogEntry.findPaginated(new Document(), skip, pageSize, (auditLog, error) -> { + // TODO: DO THIS BETTER (SAME FOR PUNISHMENTS, IP BANS, AND GRANTS + AuditLogEntry.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (auditLog, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/grants/GETGrants.java b/src/main/java/net/frozenorb/apiv3/route/grants/GETGrants.java index 0af423b..f97813a 100644 --- a/src/main/java/net/frozenorb/apiv3/route/grants/GETGrants.java +++ b/src/main/java/net/frozenorb/apiv3/route/grants/GETGrants.java @@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.model.Grant; import net.frozenorb.apiv3.util.ErrorUtils; +import org.bson.Document; public final class GETGrants implements Handler { @@ -13,7 +14,7 @@ public final class GETGrants 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")); - Grant.findAllPaginated(skip, pageSize, (grants, error) -> { + Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else { diff --git a/src/main/java/net/frozenorb/apiv3/route/ipBans/GETIpBans.java b/src/main/java/net/frozenorb/apiv3/route/ipBans/GETIpBans.java index ff605bd..a92ee28 100644 --- a/src/main/java/net/frozenorb/apiv3/route/ipBans/GETIpBans.java +++ b/src/main/java/net/frozenorb/apiv3/route/ipBans/GETIpBans.java @@ -5,6 +5,7 @@ import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.model.IpBan; import net.frozenorb.apiv3.util.ErrorUtils; +import org.bson.Document; public final class GETIpBans implements Handler { @@ -13,7 +14,7 @@ public final class GETIpBans 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")); - IpBan.findAllPaginated(skip, pageSize, (grants, error) -> { + IpBan.findPaginated(ctx.request().getParam("userIp") == null ? new Document() : new Document("userIp", ctx.request().getParam("userIp")), skip, pageSize, (grants, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else { 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 3c1c280..c634378 100644 --- a/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java +++ b/src/main/java/net/frozenorb/apiv3/route/punishments/GETPunishments.java @@ -5,16 +5,16 @@ import io.vertx.ext.web.RoutingContext; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.model.Punishment; import net.frozenorb.apiv3.util.ErrorUtils; +import org.bson.Document; public final class GETPunishments implements Handler { public void handle(RoutingContext ctx) { - // USER PARAM 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")); - Punishment.findAllPaginated(skip, pageSize, (grants, error) -> { + Punishment.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> { if (error != null) { ErrorUtils.respondInternalError(ctx, error); } else {