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 53d4194c856aa676cd2b8d8fe5e2c5f5c13778e7..8e3253e85f4bc3cf7ea9b2830144169f607ce3ea 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,12 +2,14 @@ package hdm.mi.sthbackend.controller; import hdm.mi.sthbackend.dto.PlayerDTO; -import hdm.mi.sthbackend.exeptions.*; 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.Tournament; import hdm.mi.sthbackend.service.TournamentService; +import hdm.mi.sthbackend.types.TeamName; +import hdm.mi.sthbackend.types.TournamentName; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -43,9 +45,9 @@ public class TournamentController { } @PostMapping("/tournaments/{tournamentId}/teams") - public Team createTeam(@PathVariable UUID tournamentId, - @RequestBody String teamName) throws TournamentIdNotFoundException { - return service.createAndAddTeamToTournament(tournamentId, teamName); + public TeamDTO createTeam(@PathVariable UUID tournamentId, + @RequestBody TeamName teamName) throws TournamentIdNotFoundException { + return service.createAndAddTeamToTournament(tournamentId, teamName.getName()); } @DeleteMapping("/tournaments/{tournamentId}/teams/{teamId}") @@ -55,7 +57,7 @@ public class TournamentController { } @PostMapping("/teams/{teamId}/addPlayer") - public Player addPlayerToTeam(@PathVariable UUID teamId, + public PlayerDTO addPlayerToTeam(@PathVariable UUID teamId, @RequestBody String playerName) throws Exception { return service.addPlayerToTeam(teamId, playerName); } @@ -65,19 +67,26 @@ public class TournamentController { @PathVariable UUID playerId) throws PlayerIdNotFoundException, TeamIdNotFoundException { return service.removePlayerFromTeam(teamId, playerId); } - @PatchMapping("/tournaments/{tournamentId}/match/{matchId}") - public UUID determineWinner(@PathVariable UUID tournamentId, - @PathVariable UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException, WinnerNotDeterminedException { - return service.determineWinner(tournamentId, matchId); + + @PatchMapping("/match/{matchId}/determineWinner") + public UUID determineWinner(@PathVariable UUID matchId) throws MatchIdNotFoundException, WinnerNotDeterminedException { + return service.determineWinner(matchId); } /** * Tournament Endpoints */ + @GetMapping("/tournaments/{tournamentId}") + public TournamentDTO findTournamentById(@PathVariable UUID tournamentId) throws TournamentIdNotFoundException { + return service.getTournament(tournamentId); + } + @PostMapping("/tournaments") - public Tournament createTournament(@RequestBody String tournamentName) { - return service.createTournament(tournamentName); + public TournamentDTO createTournament(@RequestBody TournamentName params) { + return service.createTournament(params.getName()); } + + }