diff --git a/src/main/java/de/grimsi/gameyfin/rest/GamesController.java b/src/main/java/de/grimsi/gameyfin/rest/GamesController.java new file mode 100644 index 0000000..0b7ac70 --- /dev/null +++ b/src/main/java/de/grimsi/gameyfin/rest/GamesController.java @@ -0,0 +1,33 @@ +package de.grimsi.gameyfin.rest; + +import de.grimsi.gameyfin.entities.DetectedGame; +import de.grimsi.gameyfin.service.GameService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +/** + * This controller handles logic related to detected games. + */ +@RestController +@RequestMapping("/games") +@RequiredArgsConstructor +public class GamesController { + + private final GameService gameService; + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public List getAllGames() { + return gameService.getAllDetectedGames(); + } + + @GetMapping(value = "/game-mappings", produces = MediaType.APPLICATION_JSON_VALUE) + public Map getGameMappings() { + return gameService.getAllMappings(); + } +} diff --git a/src/main/java/de/grimsi/gameyfin/rest/GameyfinDevController.java b/src/main/java/de/grimsi/gameyfin/rest/GameyfinDevController.java deleted file mode 100644 index 2ed9d6b..0000000 --- a/src/main/java/de/grimsi/gameyfin/rest/GameyfinDevController.java +++ /dev/null @@ -1,71 +0,0 @@ -package de.grimsi.gameyfin.rest; - -import de.grimsi.gameyfin.entities.DetectedGame; -import de.grimsi.gameyfin.entities.UnmappableFile; -import de.grimsi.gameyfin.service.FilesystemService; -import de.grimsi.gameyfin.service.GameService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.io.Resource; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - -@RestController -public class GameyfinDevController { - - @Autowired - private FilesystemService filesystemService; - - @Autowired - private GameService gameService; - - @GetMapping(value = "/dev/gameFiles", produces = MediaType.APPLICATION_JSON_VALUE) - public List getAllGameFiles() { - return filesystemService.getGameFiles().stream().map(Path::toString).toList(); - } - - @GetMapping(value = "/dev/games", produces = MediaType.APPLICATION_JSON_VALUE) - public List getAllGames() { - return gameService.getAllDetectedGames(); - } - - @GetMapping(value = "/dev/images/{imageId}", produces = MediaType.IMAGE_PNG_VALUE) - public Resource getCoverImageForGame(@PathVariable String imageId) { - return filesystemService.getImage(imageId); - } - - @GetMapping(value = "/dev/scan", produces = MediaType.APPLICATION_JSON_VALUE) - public void scanLibrary() { - filesystemService.scanGameLibrary(); - } - - @GetMapping(value = "/dev/cache/download") - public void downloadCovers() { - filesystemService.downloadGameCovers(); - filesystemService.downloadGameScreenshots(); - filesystemService.downloadCompanyLogos(); - } - - - @GetMapping(value = "/dev/unmappedFiles", produces = MediaType.APPLICATION_JSON_VALUE) - public List getUnmappedFiles() { - return gameService.getAllUnmappedFiles(); - } - - @GetMapping(value = "/dev/gameMappings", produces = MediaType.APPLICATION_JSON_VALUE) - public Map getGameMappings() { - return gameService.getAllMappings(); - } - - @PostMapping(value = "/dev/unmappedFiles/{unmappedGameId}/mapTo/{igdbSlug}", produces = MediaType.APPLICATION_JSON_VALUE) - public DetectedGame mapGameManually(@PathVariable Long unmappedGameId, @PathVariable String igdbSlug) { - return gameService.mapUnmappedFile(unmappedGameId, igdbSlug); - } - -} diff --git a/src/main/java/de/grimsi/gameyfin/rest/ImageController.java b/src/main/java/de/grimsi/gameyfin/rest/ImageController.java new file mode 100644 index 0000000..1d1ef87 --- /dev/null +++ b/src/main/java/de/grimsi/gameyfin/rest/ImageController.java @@ -0,0 +1,26 @@ +package de.grimsi.gameyfin.rest; + +import de.grimsi.gameyfin.service.FilesystemService; +import lombok.RequiredArgsConstructor; +import org.springframework.core.io.Resource; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * This controller handles functionality for images. + */ +@RestController +@RequestMapping("/images") +@RequiredArgsConstructor +public class ImageController { + + private final FilesystemService filesystemService; + + @GetMapping(value = "/{imageId}", produces = MediaType.IMAGE_PNG_VALUE) + public Resource getCoverImageForGame(@PathVariable String imageId) { + return filesystemService.getImage(imageId); + } +} diff --git a/src/main/java/de/grimsi/gameyfin/rest/LibraryController.java b/src/main/java/de/grimsi/gameyfin/rest/LibraryController.java new file mode 100644 index 0000000..de788a6 --- /dev/null +++ b/src/main/java/de/grimsi/gameyfin/rest/LibraryController.java @@ -0,0 +1,43 @@ +package de.grimsi.gameyfin.rest; + +import de.grimsi.gameyfin.service.FilesystemService; +import lombok.RequiredArgsConstructor; +import org.springframework.data.repository.query.Param; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.nio.file.Path; +import java.util.List; + +/** + * This controller handles functionality of the library. + */ +@RestController +@RequestMapping("/library") +@RequiredArgsConstructor +public class LibraryController { + + private final FilesystemService filesystemService; + + @GetMapping(value = "/scan", produces = MediaType.APPLICATION_JSON_VALUE) + public void scanLibrary(@RequestParam("download_images") boolean downloadImages) { + filesystemService.scanGameLibrary(); + + if(downloadImages) populateCache(); + } + + @GetMapping(value = "/populate-cache") + public void populateCache() { + filesystemService.downloadGameCovers(); + filesystemService.downloadGameScreenshots(); + filesystemService.downloadCompanyLogos(); + } + + @GetMapping(value = "/files", produces = MediaType.APPLICATION_JSON_VALUE) + public List getAllFiles() { + return filesystemService.getGameFiles().stream().map(Path::toString).toList(); + } +} diff --git a/src/main/java/de/grimsi/gameyfin/rest/UnmappedFileController.java b/src/main/java/de/grimsi/gameyfin/rest/UnmappedFileController.java new file mode 100644 index 0000000..d6600e6 --- /dev/null +++ b/src/main/java/de/grimsi/gameyfin/rest/UnmappedFileController.java @@ -0,0 +1,29 @@ +package de.grimsi.gameyfin.rest; + +import de.grimsi.gameyfin.entities.DetectedGame; +import de.grimsi.gameyfin.entities.UnmappableFile; +import de.grimsi.gameyfin.service.GameService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/unmapped-files") +@RequiredArgsConstructor +public class UnmappedFileController { + + private final GameService gameService; + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public List getUnmappedFiles() { + return gameService.getAllUnmappedFiles(); + } + + @PostMapping(value = "/{unmappedFileId}/map-to/{igdbSlug}", produces = MediaType.APPLICATION_JSON_VALUE) + public DetectedGame mapGameManually(@PathVariable Long unmappedFileId, @PathVariable String igdbSlug) { + return gameService.mapUnmappedFile(unmappedFileId, igdbSlug); + } + +}