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 8e3253e85f4bc3cf7ea9b2830144169f607ce3ea..8a9061515631b474a37d4a4e71030425db6e6426 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 @@ -1,13 +1,14 @@ package hdm.mi.sthbackend.controller; +import hdm.mi.sthbackend.dto.MatchDTO; import hdm.mi.sthbackend.dto.PlayerDTO; import hdm.mi.sthbackend.dto.TeamDTO; import hdm.mi.sthbackend.dto.TournamentDTO; import hdm.mi.sthbackend.exeptions.*; -import hdm.mi.sthbackend.model.Player; -import hdm.mi.sthbackend.model.Team; +import hdm.mi.sthbackend.model.Match; import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.types.TeamMatchScore; import hdm.mi.sthbackend.types.TeamName; import hdm.mi.sthbackend.types.TournamentName; import lombok.AllArgsConstructor; @@ -46,7 +47,7 @@ public class TournamentController { @PostMapping("/tournaments/{tournamentId}/teams") public TeamDTO createTeam(@PathVariable UUID tournamentId, - @RequestBody TeamName teamName) throws TournamentIdNotFoundException { + @RequestBody TeamName teamName) throws TournamentIdNotFoundException { return service.createAndAddTeamToTournament(tournamentId, teamName.getName()); } @@ -58,7 +59,7 @@ public class TournamentController { @PostMapping("/teams/{teamId}/addPlayer") public PlayerDTO addPlayerToTeam(@PathVariable UUID teamId, - @RequestBody String playerName) throws Exception { + @RequestBody String playerName) throws Exception { return service.addPlayerToTeam(teamId, playerName); } @@ -68,6 +69,26 @@ public class TournamentController { return service.removePlayerFromTeam(teamId, playerId); } + @PatchMapping("/teams/{teamId}/updateTeamName") + public TeamDTO updateTeamName(@PathVariable UUID teamId, @RequestBody TeamName newTeamName) throws TeamIdNotFoundException { + return service.updateTeamName(teamId, newTeamName.getName()); + } + + + + /** + * Match Endpoints + */ + @PatchMapping("matches/{matchId}/teams/{teamId}/assignTeamToMatch") + public MatchDTO assignTeamToMatch(@PathVariable UUID matchId, @PathVariable UUID teamId, @RequestBody TeamMatchScore score) throws MatchIdNotFoundException { + return service.assignTeamToMatch(matchId, teamId, score.getScore()); + } + + @PatchMapping("matches/{matchId}/teams/{teamId}/updateScore") + public MatchDTO updateScore(@PathVariable UUID matchId, @PathVariable UUID teamId, @RequestBody TeamMatchScore newScore) throws MatchIdNotFoundException, TeamIdNotFoundException { + return service.updateTeamScore(matchId, teamId, newScore.getScore()); + } + @PatchMapping("/match/{matchId}/determineWinner") public UUID determineWinner(@PathVariable UUID matchId) throws MatchIdNotFoundException, WinnerNotDeterminedException { return service.determineWinner(matchId); @@ -87,6 +108,14 @@ public class TournamentController { return service.createTournament(params.getName()); } + @DeleteMapping("/tournaments/{tournamentId}") + public TournamentDTO deleteTournament(@PathVariable UUID tournamentId) throws TournamentIdNotFoundException { + return service.deleteTournament(tournamentId); + } + @PatchMapping("/tournaments/{tournamentId}/updateName") + public UUID updateTournamentName(@PathVariable UUID tournamentId, @RequestBody String newTournamentName) throws TournamentIdNotFoundException { + return service.updateTournamentName(tournamentId, newTournamentName); + } } 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 3fae9fce518c2e5c75186311b41234477be6347c..857ff616f35fefbb2b3b904dc6217e11fd1c7343 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 @@ -1,5 +1,6 @@ package hdm.mi.sthbackend.service; +import hdm.mi.sthbackend.dto.MatchDTO; import hdm.mi.sthbackend.dto.PlayerDTO; import hdm.mi.sthbackend.dto.TeamDTO; import hdm.mi.sthbackend.dto.TournamentDTO; @@ -13,6 +14,7 @@ import hdm.mi.sthbackend.repository.IMatchRepository; import hdm.mi.sthbackend.repository.IPlayerRepository; import hdm.mi.sthbackend.repository.ITeamRepository; import hdm.mi.sthbackend.repository.ITournamentRepository; +import hdm.mi.sthbackend.types.TeamMatchScore; import lombok.AllArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -164,16 +166,17 @@ public class TournamentService { return winnerTeamId; } - public void assignTeamToMatch(UUID tournamentId, UUID matchId, UUID teamId, int score) throws TournamentIdNotFoundException, MatchIdNotFoundException { + public MatchDTO assignTeamToMatch(UUID matchId, UUID teamId, int score) throws MatchIdNotFoundException { Match match = matchRepository.findById(matchId).orElseThrow(() -> new MatchIdNotFoundException(matchId)); match.getTeamScores().put(teamId,score); matchRepository.save(match); - log.debug("Team " + teamId + " assign to Match " + matchId + " in Tournament " + tournamentId); + log.debug("Team " + teamId + " assign to Match " + matchId ); + return mapper.mapToMatchDTO(match); } - public void updateTeamScore(UUID tournamentId, UUID matchId, UUID teamId, int newScore)throws TournamentIdNotFoundException, MatchIdNotFoundException, TeamIdNotFoundException{ + public MatchDTO updateTeamScore(UUID matchId, UUID teamId, int newScore)throws MatchIdNotFoundException, TeamIdNotFoundException{ Match match = matchRepository.findById(matchId).orElseThrow(() -> new MatchIdNotFoundException(matchId)); if (!match.getTeamScores().containsKey(teamId)) { @@ -182,16 +185,17 @@ public class TournamentService { match.getTeamScores().put(teamId, newScore); matchRepository.save(match); log.debug("Score of Team " + teamId + " updated to " + newScore); + return mapper.mapToMatchDTO(match); } - public UUID updateTeamName(UUID teamId, String newTeamName) throws TeamIdNotFoundException { + public TeamDTO updateTeamName(UUID teamId, String newTeamName) throws TeamIdNotFoundException { Team team = teamRepository.findById(teamId) .orElseThrow(() -> new TeamIdNotFoundException(teamId)); team.setTeamName(newTeamName); teamRepository.save(team); log.debug("Teamname of " + teamId + " updated to " + newTeamName); - return teamId; + return mapper.mapToTeamDTO(team); } public UUID updateTournamentName(UUID tournamentId, String newTournamentName)throws TournamentIdNotFoundException{ @@ -211,12 +215,13 @@ public class TournamentService { return mapper.mapToTournamentDTO(tournament); } - public void deleteTournament(UUID tournamentId) throws TournamentIdNotFoundException { + public TournamentDTO deleteTournament(UUID tournamentId) throws TournamentIdNotFoundException { Tournament tournamentToDelete = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); tournamentRepository.delete(tournamentToDelete); log.debug("Tournament " + tournamentId + " has been deleted"); + return mapper.mapToTournamentDTO(tournamentToDelete); } /* diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamMatchScore.java b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamMatchScore.java new file mode 100644 index 0000000000000000000000000000000000000000..5d7b5828b126a76fa4cc97f1f17066bb127af6d0 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamMatchScore.java @@ -0,0 +1,9 @@ +package hdm.mi.sthbackend.types; + +import lombok.Getter; + +@Getter +public class TeamMatchScore { + int score; + +}