From 39817d154c1e7de2c0bbae173515de1ea338bf96 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Mon, 25 Apr 2016 17:27:53 -0400 Subject: [PATCH] Push non-completed code so I can move to my desktop! --- src/main/java/net/frozenorb/apiv3/APIv3.java | 4 +++- .../apiv3/routes/grants/GETUserGrants.java | 23 +++++++++++++++++++ .../routes/punishments/GETPunishment.java | 15 ++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/frozenorb/apiv3/routes/grants/GETUserGrants.java create mode 100644 src/main/java/net/frozenorb/apiv3/routes/punishments/GETPunishment.java diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 8c85108..ece63e3 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -15,6 +15,7 @@ import net.frozenorb.apiv3.routes.grants.DELETEGrant; import net.frozenorb.apiv3.routes.grants.GETGrants; import net.frozenorb.apiv3.routes.grants.POSTUserGrant; import net.frozenorb.apiv3.routes.punishments.DELETEPunishment; +import net.frozenorb.apiv3.routes.punishments.GETPunishment; import net.frozenorb.apiv3.routes.punishments.GETPunishments; import net.frozenorb.apiv3.routes.punishments.POSTUserPunish; import net.frozenorb.apiv3.routes.servers.GETServer; @@ -72,8 +73,9 @@ public final class APIv3 { post("/user/:id:/grant", new POSTUserGrant(), gson::toJson); delete("/punishment/:id", new DELETEPunishment(), gson::toJson); + get("/punishment/:id", new GETPunishment(), gson::toJson); get("/punishments", new GETPunishments(), gson::toJson); - post("/user/:id:/punish", new POSTUserPunish(), gson::toJson); + post("/user/:id:/punish", new erPunish(), gson::toJson); get("/server/:id", new GETServer(), gson::toJson); get("/servers", new GETServers(), gson::toJson); diff --git a/src/main/java/net/frozenorb/apiv3/routes/grants/GETUserGrants.java b/src/main/java/net/frozenorb/apiv3/routes/grants/GETUserGrants.java new file mode 100644 index 0000000..8989036 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/grants/GETUserGrants.java @@ -0,0 +1,23 @@ +package net.frozenorb.apiv3.routes.grants; + +import net.frozenorb.apiv3.APIv3; +import net.frozenorb.apiv3.models.Grant; +import net.frozenorb.apiv3.models.User; +import net.frozenorb.apiv3.weirdStuff.ErrorUtils; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class GETUserGrants implements Route { + + public Object handle(Request req, Response res) { + User target = User.byIdOrName(req.params("id")); + + if (target == null) { + return ErrorUtils.notFound("User", req.params("id")); + } + + return APIv3.getDatastore().createQuery(Grant.class).order("addedAt").limit(limit).offset(offset).asList(); + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/punishments/GETPunishment.java b/src/main/java/net/frozenorb/apiv3/routes/punishments/GETPunishment.java new file mode 100644 index 0000000..4c8a67e --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/punishments/GETPunishment.java @@ -0,0 +1,15 @@ +package net.frozenorb.apiv3.routes.punishments; + +import net.frozenorb.apiv3.models.Punishment; +import net.frozenorb.apiv3.models.Server; +import spark.Request; +import spark.Response; +import spark.Route; + +public final class GETPunishment implements Route { + + public Object handle(Request req, Response res) { + return Punishment.byId(req.params("id")); + } + +} \ No newline at end of file