diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index ad54d96..80235d6 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -12,6 +12,7 @@ import net.frozenorb.apiv3.filters.AuthorizationFilter; import net.frozenorb.apiv3.filters.ContentTypeFilter; import net.frozenorb.apiv3.routes.GETDump; import net.frozenorb.apiv3.routes.announcements.GETAnnouncements; +import net.frozenorb.apiv3.routes.auditLog.GETAuditLog; import net.frozenorb.apiv3.routes.chatFilterList.GETChatFilterList; import net.frozenorb.apiv3.routes.grants.DELETEGrant; import net.frozenorb.apiv3.routes.grants.GETGrants; @@ -93,6 +94,7 @@ public final class APIv3 { exception(Exception.class, new LoggingExceptionHandler()); get("/announcements", new GETAnnouncements(), gson::toJson); + get("/auditLog", new GETAuditLog(), gson::toJson); get("/chatFilterList", new GETChatFilterList(), gson::toJson); delete("/grant/:id", new DELETEGrant(), gson::toJson); get("/grants", new GETGrants(), gson::toJson); diff --git a/src/main/java/net/frozenorb/apiv3/models/NotificationTemplate.java b/src/main/java/net/frozenorb/apiv3/models/NotificationTemplate.java index 8d11b1e..c70c7f5 100644 --- a/src/main/java/net/frozenorb/apiv3/models/NotificationTemplate.java +++ b/src/main/java/net/frozenorb/apiv3/models/NotificationTemplate.java @@ -5,6 +5,7 @@ import net.frozenorb.apiv3.APIv3; import org.mongodb.morphia.annotations.Entity; import org.mongodb.morphia.annotations.Id; +import java.util.List; import java.util.Map; @Entity(value = "notificationTemplates", noClassnameStored = true) @@ -18,6 +19,10 @@ public final class NotificationTemplate { return APIv3.getDatastore().createQuery(NotificationTemplate.class).field("id").equalIgnoreCase(id).get(); } + public static List values() { + return APIv3.getDatastore().createQuery(NotificationTemplate.class).asList(); + } + public NotificationTemplate() {} // For Morphia public NotificationTemplate(String subject, String body) { diff --git a/src/main/java/net/frozenorb/apiv3/models/Server.java b/src/main/java/net/frozenorb/apiv3/models/Server.java index 03cd0d8..de16b4f 100644 --- a/src/main/java/net/frozenorb/apiv3/models/Server.java +++ b/src/main/java/net/frozenorb/apiv3/models/Server.java @@ -43,4 +43,8 @@ public final class Server { this.players = new HashSet<>(); } + public void delete() { + APIv3.getDatastore().delete(this); + } + } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java b/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java index bb0cb93..513a1be 100644 --- a/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java +++ b/src/main/java/net/frozenorb/apiv3/models/ServerGroup.java @@ -53,4 +53,8 @@ public final class ServerGroup { ); } + public void delete() { + APIv3.getDatastore().delete(this); + } + } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/auditLog/GETAuditLog.java b/src/main/java/net/frozenorb/apiv3/routes/auditLog/GETAuditLog.java new file mode 100644 index 0000000..e590add --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/auditLog/GETAuditLog.java @@ -0,0 +1,19 @@ +package net.frozenorb.apiv3.routes.auditLog; + +import net.frozenorb.apiv3.APIv3; +import net.frozenorb.apiv3.models.AuditLogEntry; +import net.frozenorb.apiv3.models.Grant; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class GETAuditLog implements Route { + + public Object handle(Request req, Response res) { + int limit = req.queryParams("limit") == null ? 100 : Integer.parseInt(req.queryParams("limit")); + int offset = req.queryParams("offset") == null ? 0 : Integer.parseInt(req.queryParams("offset")); + + return APIv3.getDatastore().createQuery(AuditLogEntry.class).order("addedAt").limit(limit).offset(offset).asList(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/grants/GETGrants.java b/src/main/java/net/frozenorb/apiv3/routes/grants/GETGrants.java index 33a03c0..e3f9ea6 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/grants/GETGrants.java +++ b/src/main/java/net/frozenorb/apiv3/routes/grants/GETGrants.java @@ -12,7 +12,7 @@ public final class GETGrants implements Route { int limit = req.queryParams("limit") == null ? 100 : Integer.parseInt(req.queryParams("limit")); int offset = req.queryParams("offset") == null ? 0 : Integer.parseInt(req.queryParams("offset")); - return APIv3.getDatastore().createQuery(Grant.class).order("addedAt").limit(limit).offset(offset).asList(); + return APIv3.getDatastore().createQuery(Grant.class).order("performedAt").limit(limit).offset(offset).asList(); } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/notificationTemplate/DELETENotificationTemplate.java b/src/main/java/net/frozenorb/apiv3/routes/notificationTemplate/DELETENotificationTemplate.java new file mode 100644 index 0000000..ef2ff46 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/notificationTemplate/DELETENotificationTemplate.java @@ -0,0 +1,23 @@ +package net.frozenorb.apiv3.routes.notificationTemplate; + +import net.frozenorb.apiv3.models.NotificationTemplate; +import net.frozenorb.apiv3.models.Rank; +import net.frozenorb.apiv3.utils.ErrorUtils; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class DELETENotificationTemplate implements Route { + + public Object handle(Request req, Response res) { + NotificationTemplate notificationTemplate = NotificationTemplate.byId(req.params("id")); + + if (notificationTemplate == null) { + return ErrorUtils.notFound("Notification template", req.params("id")); + } + + notificationTemplate.delete(); + return notificationTemplate; + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/ranks/DELETERank.java b/src/main/java/net/frozenorb/apiv3/routes/ranks/DELETERank.java new file mode 100644 index 0000000..7fcaab0 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/ranks/DELETERank.java @@ -0,0 +1,23 @@ +package net.frozenorb.apiv3.routes.ranks; + +import net.frozenorb.apiv3.models.Rank; +import net.frozenorb.apiv3.models.ServerGroup; +import net.frozenorb.apiv3.utils.ErrorUtils; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class DELETERank implements Route { + + public Object handle(Request req, Response res) { + Rank rank = Rank.byId(req.params("id")); + + if (rank == null) { + return ErrorUtils.notFound("Rank", req.params("id")); + } + + rank.delete(); + return rank; + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/serverGroups/DELETEServerGroup.java b/src/main/java/net/frozenorb/apiv3/routes/serverGroups/DELETEServerGroup.java new file mode 100644 index 0000000..f33fbce --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/serverGroups/DELETEServerGroup.java @@ -0,0 +1,23 @@ +package net.frozenorb.apiv3.routes.serverGroups; + +import net.frozenorb.apiv3.models.Server; +import net.frozenorb.apiv3.models.ServerGroup; +import net.frozenorb.apiv3.utils.ErrorUtils; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class DELETEServerGroup implements Route { + + public Object handle(Request req, Response res) { + ServerGroup serverGroup = ServerGroup.byId(req.params("id")); + + if (serverGroup == null) { + return ErrorUtils.notFound("Server group", req.params("id")); + } + + serverGroup.delete(); + return serverGroup; + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/servers/DELETEServer.java b/src/main/java/net/frozenorb/apiv3/routes/servers/DELETEServer.java new file mode 100644 index 0000000..8333b89 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/servers/DELETEServer.java @@ -0,0 +1,22 @@ +package net.frozenorb.apiv3.routes.servers; + +import net.frozenorb.apiv3.models.Server; +import net.frozenorb.apiv3.utils.ErrorUtils; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class DELETEServer implements Route { + + public Object handle(Request req, Response res) { + Server server = Server.byId(req.params("id")); + + if (server == null) { + return ErrorUtils.notFound("Server", req.params("id")); + } + + server.delete(); + return server; + } + +} \ No newline at end of file