Added additional check if a game with a slug exists, so the user does not overwrite a mapping accidentally

This commit is contained in:
Simon Grimme
2022-07-16 03:07:33 +02:00
parent 2a33fb1d6b
commit 937c440cdf
2 changed files with 5 additions and 0 deletions
@@ -6,4 +6,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface DetectedGameRepository extends JpaRepository<DetectedGame, String> {
boolean existsByPath(String path);
boolean existsBySlug(String slug);
}
@@ -36,9 +36,13 @@ public class GameService {
}
public DetectedGame mapUnmappedFile(Long unmappedGameId, String igdbSlug) {
UnmappableFile unmappableFile = unmappableFileRepository.findById(unmappedGameId)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Unmapped file with id '%d' does not exist.".formatted(unmappedGameId)));
if(detectedGameRepository.existsBySlug(igdbSlug))
throw new ResponseStatusException(HttpStatus.CONFLICT, "Game with slug '%s' already exists in database.".formatted(igdbSlug));
Igdb.Game igdbGame = igdbWrapper.getGameBySlug(igdbSlug)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Game with slug '%s' does not exist on IGDB.".formatted(igdbSlug)));