Add some routes

This commit is contained in:
Colin McDonald 2016-04-30 20:20:12 -04:00
parent 583f91b45e
commit e38eb0894f
10 changed files with 126 additions and 1 deletions

View File

@ -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);

View File

@ -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<NotificationTemplate> values() {
return APIv3.getDatastore().createQuery(NotificationTemplate.class).asList();
}
public NotificationTemplate() {} // For Morphia
public NotificationTemplate(String subject, String body) {

View File

@ -43,4 +43,8 @@ public final class Server {
this.players = new HashSet<>();
}
public void delete() {
APIv3.getDatastore().delete(this);
}
}

View File

@ -53,4 +53,8 @@ public final class ServerGroup {
);
}
public void delete() {
APIv3.getDatastore().delete(this);
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}