WIP: Proceed with frontend implementation

This commit is contained in:
Simon Grimme
2022-07-22 12:54:39 +02:00
parent 38028b7e49
commit a06dfa7c47
14 changed files with 96 additions and 50 deletions
@@ -0,0 +1,12 @@
package de.grimsi.gameyfin.dto;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class GameOverviewDto {
private String slug;
private String title;
private String coverId;
}
@@ -1,6 +1,7 @@
package de.grimsi.gameyfin.mapper;
import com.igdb.proto.Igdb;
import de.grimsi.gameyfin.dto.GameOverviewDto;
import de.grimsi.gameyfin.entities.DetectedGame;
import de.grimsi.gameyfin.util.ProtobufUtils;
@@ -40,6 +41,14 @@ public class GameMapper {
.build();
}
public static GameOverviewDto toGameOverviewDto(DetectedGame game) {
return GameOverviewDto.builder()
.slug(game.getSlug())
.title(game.getTitle())
.coverId(game.getCoverId())
.build();
}
private static boolean hasOfflineCoop(List<Igdb.MultiplayerMode> modes) {
return modes.stream().anyMatch(Igdb.MultiplayerMode::getOfflinecoop);
}
@@ -1,10 +1,12 @@
package de.grimsi.gameyfin.rest;
import de.grimsi.gameyfin.dto.GameOverviewDto;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -26,8 +28,20 @@ public class GamesController {
return gameService.getAllDetectedGames();
}
@GetMapping(value = "/game/{slug}", produces = MediaType.APPLICATION_JSON_VALUE)
public DetectedGame getGame(@PathVariable String slug) {
return gameService.getDetectedGame(slug);
}
@GetMapping(value = "/game-overviews", produces = MediaType.APPLICATION_JSON_VALUE)
public List<GameOverviewDto> getGameOverviews() {
return gameService.getGameOverviews();
}
@GetMapping(value = "/game-mappings", produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, String> getGameMappings() {
return gameService.getAllMappings();
}
}
@@ -1,6 +1,7 @@
package de.grimsi.gameyfin.service;
import com.igdb.proto.Igdb;
import de.grimsi.gameyfin.dto.GameOverviewDto;
import de.grimsi.gameyfin.entities.DetectedGame;
import de.grimsi.gameyfin.entities.UnmappableFile;
import de.grimsi.gameyfin.igdb.IgdbWrapper;
@@ -33,6 +34,10 @@ public class GameService {
return detectedGameRepository.findAll();
}
public DetectedGame getDetectedGame(String slug) {
return detectedGameRepository.findById(slug).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Game with slug '%s' not found in library.".formatted(slug)));
}
public List<UnmappableFile> getAllUnmappedFiles() {
return unmappableFileRepository.findAll();
}
@@ -41,6 +46,10 @@ public class GameService {
return detectedGameRepository.findAll().stream().collect(Collectors.toMap(DetectedGame::getPath, DetectedGame::getTitle));
}
public List<GameOverviewDto> getGameOverviews() {
return detectedGameRepository.findAll().stream().map(GameMapper::toGameOverviewDto).toList();
}
public DetectedGame mapUnmappedFile(Long unmappedGameId, String igdbSlug) {
UnmappableFile unmappableFile = unmappableFileRepository.findById(unmappedGameId)