Rename routers to fit their respective routes better

This commit is contained in:
Colin McDonald 2016-03-06 00:01:39 -05:00
parent 516f831277
commit 3f5c9ed3a0
8 changed files with 46 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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