Server controller
This commit is contained in:
parent
68a3000498
commit
d14cd8d0b4
@ -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
|
||||
*/
|
||||
|
42
src/main/java/me/braydon/mc/controller/ServerController.java
Normal file
42
src/main/java/me/braydon/mc/controller/ServerController.java
Normal file
@ -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<MinecraftServer> getServer(@PathVariable @NonNull String platform,
|
||||
@PathVariable @NonNull String hostname
|
||||
) {
|
||||
return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname));
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user