From 3f5c9ed3a0dd58120f9f5034a50155448f050c8c Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 6 Mar 2016 00:01:39 -0500 Subject: [PATCH] Rename routers to fit their respective routes better --- src/main/java/net/frozenorb/apiv3/APIv3.java | 12 +++---- .../{GrantRouter.java => GrantsRouter.java} | 2 +- ...ntRouter.java => NotificationsRouter.java} | 2 +- ...UserRouter.java => PunishmentsRouter.java} | 2 +- .../apiv3/routes/ServerGroupRouter.java | 18 ---------- ...ionRouter.java => ServerGroupsRouter.java} | 2 +- .../{ServerRouter.java => ServersRouter.java} | 2 +- .../frozenorb/apiv3/routes/UsersRouter.java | 35 +++++++++++++++++++ 8 files changed, 46 insertions(+), 29 deletions(-) rename src/main/java/net/frozenorb/apiv3/routes/{GrantRouter.java => GrantsRouter.java} (90%) rename src/main/java/net/frozenorb/apiv3/routes/{PunishmentRouter.java => NotificationsRouter.java} (88%) rename src/main/java/net/frozenorb/apiv3/routes/{UserRouter.java => PunishmentsRouter.java} (89%) delete mode 100644 src/main/java/net/frozenorb/apiv3/routes/ServerGroupRouter.java rename src/main/java/net/frozenorb/apiv3/routes/{NotificationRouter.java => ServerGroupsRouter.java} (89%) rename src/main/java/net/frozenorb/apiv3/routes/{ServerRouter.java => ServersRouter.java} (99%) create mode 100644 src/main/java/net/frozenorb/apiv3/routes/UsersRouter.java diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index ef623bb..55317c0 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -35,13 +35,13 @@ public final class APIv3 extends AbstractVerticle { }); rootRouter.mountSubRouter("/auditLog", AuditLogRouter.create(vertx)); - rootRouter.mountSubRouter("/grants", GrantRouter.create(vertx)); + rootRouter.mountSubRouter("/grants", GrantsRouter.create(vertx)); rootRouter.mountSubRouter("/ipLog", IPLogRouter.create(vertx)); - rootRouter.mountSubRouter("/notifications", NotificationRouter.create(vertx)); - rootRouter.mountSubRouter("/punishments", PunishmentRouter.create(vertx)); - rootRouter.mountSubRouter("/serverGroups", ServerGroupRouter.create(vertx)); - rootRouter.mountSubRouter("/servers", ServerGroupRouter.create(vertx)); - rootRouter.mountSubRouter("/users", UserRouter.create(vertx)); + rootRouter.mountSubRouter("/notifications", NotificationsRouter.create(vertx)); + rootRouter.mountSubRouter("/punishments", PunishmentsRouter.create(vertx)); + rootRouter.mountSubRouter("/serverGroups", ServerGroupsRouter.create(vertx)); + rootRouter.mountSubRouter("/servers", ServersRouter.create(vertx)); + rootRouter.mountSubRouter("/users", UsersRouter.create(vertx)); vertx.createHttpServer().requestHandler(rootRouter::accept).listen(8080); } diff --git a/src/main/java/net/frozenorb/apiv3/routes/GrantRouter.java b/src/main/java/net/frozenorb/apiv3/routes/GrantsRouter.java similarity index 90% rename from src/main/java/net/frozenorb/apiv3/routes/GrantRouter.java rename to src/main/java/net/frozenorb/apiv3/routes/GrantsRouter.java index 63c6909..419bf78 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/GrantRouter.java +++ b/src/main/java/net/frozenorb/apiv3/routes/GrantsRouter.java @@ -5,7 +5,7 @@ import io.vertx.ext.web.Router; import lombok.experimental.UtilityClass; @UtilityClass -public class GrantRouter { +public class GrantsRouter { public static Router create(Vertx vertx) { Router router = Router.router(vertx); diff --git a/src/main/java/net/frozenorb/apiv3/routes/PunishmentRouter.java b/src/main/java/net/frozenorb/apiv3/routes/NotificationsRouter.java similarity index 88% rename from src/main/java/net/frozenorb/apiv3/routes/PunishmentRouter.java rename to src/main/java/net/frozenorb/apiv3/routes/NotificationsRouter.java index 3583b84..7c68739 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/PunishmentRouter.java +++ b/src/main/java/net/frozenorb/apiv3/routes/NotificationsRouter.java @@ -5,7 +5,7 @@ import io.vertx.ext.web.Router; import lombok.experimental.UtilityClass; @UtilityClass -public class PunishmentRouter { +public class NotificationsRouter { public static Router create(Vertx vertx) { Router router = Router.router(vertx); diff --git a/src/main/java/net/frozenorb/apiv3/routes/UserRouter.java b/src/main/java/net/frozenorb/apiv3/routes/PunishmentsRouter.java similarity index 89% rename from src/main/java/net/frozenorb/apiv3/routes/UserRouter.java rename to src/main/java/net/frozenorb/apiv3/routes/PunishmentsRouter.java index 45bf5de..88b66d1 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/UserRouter.java +++ b/src/main/java/net/frozenorb/apiv3/routes/PunishmentsRouter.java @@ -5,7 +5,7 @@ import io.vertx.ext.web.Router; import lombok.experimental.UtilityClass; @UtilityClass -public class UserRouter { +public class PunishmentsRouter { public static Router create(Vertx vertx) { Router router = Router.router(vertx); diff --git a/src/main/java/net/frozenorb/apiv3/routes/ServerGroupRouter.java b/src/main/java/net/frozenorb/apiv3/routes/ServerGroupRouter.java deleted file mode 100644 index 8c98fc0..0000000 --- a/src/main/java/net/frozenorb/apiv3/routes/ServerGroupRouter.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.frozenorb.apiv3.routes; - -import io.vertx.core.Vertx; -import io.vertx.ext.web.Router; -import lombok.experimental.UtilityClass; - -@UtilityClass -public class ServerGroupRouter { - - public static Router create(Vertx vertx) { - Router router = Router.router(vertx); - - - - return router; - } - -} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/routes/NotificationRouter.java b/src/main/java/net/frozenorb/apiv3/routes/ServerGroupsRouter.java similarity index 89% rename from src/main/java/net/frozenorb/apiv3/routes/NotificationRouter.java rename to src/main/java/net/frozenorb/apiv3/routes/ServerGroupsRouter.java index 8f75426..93a0909 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/NotificationRouter.java +++ b/src/main/java/net/frozenorb/apiv3/routes/ServerGroupsRouter.java @@ -5,7 +5,7 @@ import io.vertx.ext.web.Router; import lombok.experimental.UtilityClass; @UtilityClass -public class NotificationRouter { +public class ServerGroupsRouter { public static Router create(Vertx vertx) { Router router = Router.router(vertx); diff --git a/src/main/java/net/frozenorb/apiv3/routes/ServerRouter.java b/src/main/java/net/frozenorb/apiv3/routes/ServersRouter.java similarity index 99% rename from src/main/java/net/frozenorb/apiv3/routes/ServerRouter.java rename to src/main/java/net/frozenorb/apiv3/routes/ServersRouter.java index 1b25289..b9cfe78 100644 --- a/src/main/java/net/frozenorb/apiv3/routes/ServerRouter.java +++ b/src/main/java/net/frozenorb/apiv3/routes/ServersRouter.java @@ -5,7 +5,7 @@ import io.vertx.ext.web.Router; import lombok.experimental.UtilityClass; @UtilityClass -public class ServerRouter { +public class ServersRouter { public static Router create(Vertx vertx) { Router router = Router.router(vertx); diff --git a/src/main/java/net/frozenorb/apiv3/routes/UsersRouter.java b/src/main/java/net/frozenorb/apiv3/routes/UsersRouter.java new file mode 100644 index 0000000..e470138 --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/routes/UsersRouter.java @@ -0,0 +1,35 @@ +package net.frozenorb.apiv3.routes; + +import io.vertx.core.Vertx; +import io.vertx.ext.web.Router; +import lombok.experimental.UtilityClass; +import net.frozenorb.apiv3.accessor.Users; +import net.frozenorb.apiv3.util.ErrorUtils; +import net.frozenorb.apiv3.util.JsonUtils; + +import java.util.UUID; + +@UtilityClass +public class UsersRouter { + + public static Router create(Vertx vertx) { + Router router = Router.router(vertx); + + router.get("/info/:user").handler(ctx -> { + UUID target = UUID.fromString(ctx.request().getParam("user")); + + Users.findById(target, (user, error) -> { + if (error != null) { + ctx.response().end(ErrorUtils.toResponseString(error)); + } else if (user != null) { + ctx.response().end(JsonUtils.toLiteJsonString(user)); + } else { + ctx.response().end(ErrorUtils.toResponseString("User '" + target + "' not found.")); + } + }); + }); + + return router; + } + +} \ No newline at end of file