diff --git a/jukebox/src/main/java/de/bstly/we/jukebox/controller/JukeboxController.java b/jukebox/src/main/java/de/bstly/we/jukebox/controller/JukeboxController.java index ecc7372..1e410fa 100644 --- a/jukebox/src/main/java/de/bstly/we/jukebox/controller/JukeboxController.java +++ b/jukebox/src/main/java/de/bstly/we/jukebox/controller/JukeboxController.java @@ -157,6 +157,40 @@ public class JukeboxController extends BaseController { queueList.put(getCurrentUserId(), Instant.now()); } + /** + * Current. + * + * @param response the response + * @throws JsonIOException the json IO exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @PreAuthorize("isAuthenticated()") + @GetMapping("/current") + public void current(HttpServletResponse response) throws JsonIOException, IOException { + if (!permissionManager.hasPermission(getCurrentUserId(), ParteyPermissions.PARTEY)) { + throw new EntityResponseStatusException(HttpStatus.FORBIDDEN); + } + + if (!jukeboxManager.getConfig().isActive()) { + throw new EntityResponseStatusException(HttpStatus.GONE); + } + + JsonElement status = jukeboxManager.getStatus(); + + if (status != null) { + JsonObject statusObject = status.getAsJsonObject(); + if (statusObject.has("item")) { + response.setContentType("application/json"); + response.setCharacterEncoding("UTF-8"); + response.setStatus(HttpStatus.OK.value()); + gson.toJson(statusObject.getAsJsonObject("item"), response.getWriter()); + return; + } + } + + throw new EntityResponseStatusException(HttpStatus.NO_CONTENT); + } + /** * Last. *