diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java index 0185e761e1c0b6f459841365ca2225546357f8ac..4428bb10876d07702c033f402b94320737e897cb 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/controller/TournamentController.java @@ -2,11 +2,8 @@ package hdm.mi.sthbackend.controller; import hdm.mi.sthbackend.dto.PlayerDTO; -import hdm.mi.sthbackend.exeptions.MatchIdNotFoundException; +import hdm.mi.sthbackend.exeptions.*; import hdm.mi.sthbackend.dto.TeamDTO; -import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TeamIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; import hdm.mi.sthbackend.model.Player; import hdm.mi.sthbackend.model.Team; import hdm.mi.sthbackend.model.Tournament; @@ -70,7 +67,7 @@ public class TournamentController { } @PatchMapping public UUID determineWinner(@PathVariable UUID tournamentId, - @PathVariable UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException { + @PathVariable UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException, WinnerNotDeterminedException { return service.determineWinner(tournamentId, matchId); } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/WinnerNotDeterminedException.java b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/WinnerNotDeterminedException.java new file mode 100644 index 0000000000000000000000000000000000000000..3c15f2e3641dfdf3af0b9b77483addd4ac1f4390 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/exeptions/WinnerNotDeterminedException.java @@ -0,0 +1,9 @@ +package hdm.mi.sthbackend.exeptions; + +import java.util.UUID; + +public class WinnerNotDeterminedException extends Exception{ + public WinnerNotDeterminedException(UUID match, UUID tournamentId) { + super(String.format("Winner not determined for Match %s in Tournament %s ", match.toString(), tournamentId.toString())); + } +} \ No newline at end of file diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java b/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java index 757f74f57002f796e2aeba5e48b441533e6e058f..531845e596e5a932d5cc26df7e6bdc6e22b41bad 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/service/TournamentService.java @@ -2,10 +2,7 @@ package hdm.mi.sthbackend.service; import hdm.mi.sthbackend.dto.PlayerDTO; import hdm.mi.sthbackend.dto.TeamDTO; -import hdm.mi.sthbackend.exeptions.MatchIdNotFoundException; -import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TeamIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; +import hdm.mi.sthbackend.exeptions.*; import hdm.mi.sthbackend.model.Match; import hdm.mi.sthbackend.model.Player; import hdm.mi.sthbackend.model.Team; @@ -147,7 +144,7 @@ public class TournamentService { return tournament; } - public UUID determineWinner (UUID tournamentId, UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException{ + public UUID determineWinner (UUID tournamentId, UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException, WinnerNotDeterminedException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -158,9 +155,9 @@ public class TournamentService { .orElseThrow(() -> new MatchIdNotFoundException(matchId)); UUID winnerTeamId = match.getTeamScores().entrySet().stream() - .max(Comparator.<Map.Entry<UUID, Number>, Double>comparing(entry -> entry.getValue().doubleValue())) + .max(Comparator.comparing(Map.Entry::getKey)) .map(Map.Entry::getKey) - .orElse(null); + .orElseThrow(() -> new WinnerNotDeterminedException(matchId,tournamentId)); match.setWinnerTeamId(winnerTeamId); tournamentRepository.save(tournament);