diff --git a/src/main/java/me/braydon/mc/controller/PlayerController.java b/src/main/java/me/braydon/mc/controller/PlayerController.java index c332b10..55baae2 100644 --- a/src/main/java/me/braydon/mc/controller/PlayerController.java +++ b/src/main/java/me/braydon/mc/controller/PlayerController.java @@ -4,6 +4,7 @@ import lombok.NonNull; import lombok.extern.log4j.Log4j2; import me.braydon.mc.exception.impl.BadRequestException; import me.braydon.mc.exception.impl.ResourceNotFoundException; +import me.braydon.mc.model.Player; import me.braydon.mc.model.cache.CachedPlayer; import me.braydon.mc.service.MojangService; import org.springframework.beans.factory.annotation.Autowired; @@ -13,7 +14,7 @@ import org.springframework.web.bind.annotation.*; /** * The controller for handling - * player related requests. + * {@link Player} related requests. * * @author Braydon */ diff --git a/src/main/java/me/braydon/mc/controller/ServerController.java b/src/main/java/me/braydon/mc/controller/ServerController.java new file mode 100644 index 0000000..e2cb788 --- /dev/null +++ b/src/main/java/me/braydon/mc/controller/ServerController.java @@ -0,0 +1,42 @@ +package me.braydon.mc.controller; + +import lombok.NonNull; +import lombok.extern.log4j.Log4j2; +import me.braydon.mc.model.MinecraftServer; +import me.braydon.mc.model.server.JavaMinecraftServer; +import me.braydon.mc.service.MojangService; +import me.braydon.mc.service.pinger.impl.JavaMinecraftServerPinger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.yaml.snakeyaml.util.EnumUtils; + +/** + * The controller for handling + * {@link MinecraftServer} related requests. + * + * @author Braydon + */ +@RestController +@RequestMapping(value = "/server", produces = MediaType.APPLICATION_JSON_VALUE) +@Log4j2(topic = "Server Controller") +public final class ServerController { + /** + * The Mojang service to use for server information. + */ + @NonNull private final MojangService mojangService; + + @Autowired + public ServerController(@NonNull MojangService mojangService) { + this.mojangService = mojangService; + } + + @GetMapping("/{platform}/{hostname}") + @ResponseBody + public ResponseEntity getServer(@PathVariable @NonNull String platform, + @PathVariable @NonNull String hostname + ) { + return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname)); + } +} \ No newline at end of file diff --git a/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java b/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java new file mode 100644 index 0000000..b51cb25 --- /dev/null +++ b/src/main/java/me/braydon/mc/exception/impl/InvalidMinecraftServerPlatform.java @@ -0,0 +1,18 @@ +package me.braydon.mc.exception.impl; + +import me.braydon.mc.model.MinecraftServer; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * This exception is raised when a {@link MinecraftServer} + * lookup is made for an invalid {@link MinecraftServer.Platform}. + * + * @author Braydon + */ +@ResponseStatus(HttpStatus.BAD_REQUEST) +public final class InvalidMinecraftServerPlatform extends RuntimeException { + public InvalidMinecraftServerPlatform() { + super("Invalid Minecraft server platform"); + } +} \ No newline at end of file