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..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,16 +1,16 @@ package hdm.mi.sthbackend.controller; +import hdm.mi.sthbackend.dto.MatchDTO; import hdm.mi.sthbackend.dto.PlayerDTO; -import hdm.mi.sthbackend.exeptions.MatchIdNotFoundException; 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; +import hdm.mi.sthbackend.dto.TournamentDTO; +import hdm.mi.sthbackend.exeptions.*; +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; import org.springframework.web.bind.annotation.*; @@ -46,9 +46,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}") @@ -58,8 +58,8 @@ public class TournamentController { } @PostMapping("/teams/{teamId}/addPlayer") - public Player addPlayerToTeam(@PathVariable UUID teamId, - @RequestBody String playerName) throws Exception { + public PlayerDTO addPlayerToTeam(@PathVariable UUID teamId, + @RequestBody String playerName) throws Exception { return service.addPlayerToTeam(teamId, playerName); } @@ -68,19 +68,54 @@ public class TournamentController { @PathVariable UUID playerId) throws PlayerIdNotFoundException, TeamIdNotFoundException { return service.removePlayerFromTeam(teamId, playerId); } - @PatchMapping - public UUID determineWinner(@PathVariable UUID tournamentId, - @PathVariable UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException { - return service.determineWinner(tournamentId, matchId); + + @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); } /** * 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()); + } + + @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/dto/MatchDTO.java b/sth-backend/src/main/java/hdm/mi/sthbackend/dto/MatchDTO.java index 736568c6565d91a73aad7beffc27e0505f282671..b214144905df840e5e593d8c8905e26375983e55 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/dto/MatchDTO.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/dto/MatchDTO.java @@ -14,7 +14,7 @@ import java.util.UUID; @NoArgsConstructor public class MatchDTO { private UUID matchId; - private Map<UUID, Number> teamScores; + private Map<UUID, Integer> teamScores; private UUID winnerTeamId; private String comment; private UUID nextMatchId; diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/dto/TournamentDTO.java b/sth-backend/src/main/java/hdm/mi/sthbackend/dto/TournamentDTO.java index 982bcda4ec27cdb8a1f2b775a4afd665c2dc1d13..b51fb0d9514ae236057144584261d5d8f97f2112 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/dto/TournamentDTO.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/dto/TournamentDTO.java @@ -18,6 +18,6 @@ import java.util.UUID; public class TournamentDTO { private UUID tournamentId; private String tournamentName; - private List<Match> matches; - private Map<UUID, Team> teams; // TODO maybe just uuid? + private Map<UUID, MatchDTO> matches; + private Map<UUID, TeamDTO> teams; } 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..bfab2d28fb66e8b86d0a6a110a320840fa57d3cd --- /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) { + super(String.format("Winner not determined for Match %s", match.toString())); + } +} \ No newline at end of file diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/mapper/ModelToDTOMapper.java b/sth-backend/src/main/java/hdm/mi/sthbackend/mapper/ModelToDTOMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..897da408c9b9c5fe212796953adc7f53b8e762cf --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/mapper/ModelToDTOMapper.java @@ -0,0 +1,122 @@ +package hdm.mi.sthbackend.mapper; + +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.MatchIdNotFoundException; +import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; +import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; +import hdm.mi.sthbackend.model.Match; +import hdm.mi.sthbackend.model.Player; +import hdm.mi.sthbackend.model.Team; +import hdm.mi.sthbackend.model.Tournament; +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 org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import java.util.stream.Collectors; + +@Component +public class ModelToDTOMapper { + private final Logger log = LogManager.getLogger(ModelToDTOMapper.class); + + ITournamentRepository tournamentRepository; + IMatchRepository matchRepository; + ITeamRepository teamRepository; + IPlayerRepository playerRepository; + + @Autowired + public ModelToDTOMapper(ITournamentRepository tournamentRepository, + IMatchRepository matchRepository, + ITeamRepository teamRepository, + IPlayerRepository playerRepository) { + this.tournamentRepository = tournamentRepository; + this.matchRepository = matchRepository; + this.teamRepository = teamRepository; + this.playerRepository = playerRepository; + } + + public TournamentDTO mapToTournamentDTO(Tournament tournament) { + Map<UUID, Match> matches = new HashMap<>(); + tournament.getMatches() + .forEach(mId -> { + try { + matches.put(mId, matchRepository.findById(mId) + .orElseThrow(() -> new MatchIdNotFoundException(mId))); + } catch (MatchIdNotFoundException e) { + log.debug("Match with id " + mId + " not found"); + } + }); + Map<UUID, MatchDTO> mappedMatches = matches.entrySet() + .stream() + .collect(Collectors.toMap(Entry::getKey, e -> mapToMatchDTO(e.getValue()))); + + Map<UUID, Team> teams = new HashMap<>(); + tournament.getTeams() + .forEach(teamId -> { + try { + teams.put(teamId, teamRepository.findById(teamId) + .orElseThrow(() -> new TournamentIdNotFoundException(teamId))); + } catch (TournamentIdNotFoundException e) { + log.debug("Team with id " + teamId + " not found"); + } + }); + Map<UUID, TeamDTO> mappedTeams = teams.entrySet() + .stream() + .collect(Collectors.toMap(Entry::getKey, e -> mapToTeamDTO(e.getValue()))); + return new TournamentDTO( + tournament.getTournamentId(), + tournament.getTournamentName(), + mappedMatches, + mappedTeams + ); + } + + public MatchDTO mapToMatchDTO(Match match) { + return new MatchDTO( + match.getMatchId(), + match.getTeamScores(), + match.getWinnerTeamId(), + match.getComment(), + match.getNextMatchId() + ); + } + + public PlayerDTO mapToPlayerDTO(Player player) { + return new PlayerDTO( + player.getPlayerId(), + player.getName() + ); + } + + public TeamDTO mapToTeamDTO(Team team) { + Map<UUID, Player> players = new HashMap<>(); + team.getTeamMembers() + .forEach(playerId -> { + try { + players.put(playerId, playerRepository.findById(playerId) + .orElseThrow(() -> new PlayerIdNotFoundException(playerId))); + } catch (PlayerIdNotFoundException e) { + log.debug("Player with id " + playerId + " not found"); + } + }); + Map<UUID, PlayerDTO> mappedPlayers = players.entrySet() + .stream() + .collect(Collectors.toMap(Entry::getKey, e -> mapToPlayerDTO(e.getValue()))); + return new TeamDTO( + team.getId(), + team.getTeamName(), + mappedPlayers + ); + } +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java index dbb97aac847b78a4c56542307c23039d2246df77..8041fd19e362850a7ff37b73a8d0be30189d02ef 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Match.java @@ -20,7 +20,7 @@ public class Match { @Id private UUID matchId; - private Map<UUID, Number> teamScores; + private Map<UUID, Integer> teamScores; @Setter private UUID winnerTeamId; diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java index cb98022bb5354856db4d00fbb881f7f74a70068c..620a1d1bee0a7f6830d7f6c9aa72b8cd79fd4907 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Team.java @@ -2,6 +2,7 @@ package hdm.mi.sthbackend.model; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -14,7 +15,7 @@ import java.util.UUID; public class Team { @Id private final UUID id; - - private final String teamName; + @Setter + private String teamName; private final List<UUID> teamMembers; } diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java deleted file mode 100644 index ee9213c4d0d3657ed173052b778d83987c79ef87..0000000000000000000000000000000000000000 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/TeamMatchScore.java +++ /dev/null @@ -1,25 +0,0 @@ -package hdm.mi.sthbackend.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -import java.util.UUID; - -@Getter -@Document("TeamMatchScore") -@AllArgsConstructor -public class TeamMatchScore { - - private static final Logger log = LogManager.getLogger(TeamMatchScore.class); - - @Id - private final UUID teamMatchScoreId; - private final UUID teamId; - @Setter - private int score; -} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java index c64e0735246ffe2afcdb20f6c3820e4af732a62c..4012eb19f9db7dbe23ab8ec65ec630972f3b39d8 100644 --- a/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/model/Tournament.java @@ -2,6 +2,7 @@ package hdm.mi.sthbackend.model; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.Setter; import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; @@ -15,10 +16,10 @@ import java.util.UUID; public class Tournament implements ITournament{ @Id private UUID tournamentId; - + @Setter private String tournamentName; - private List<Match> matches; + private List<UUID> matches; private List<UUID> teams; } 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..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,11 +1,11 @@ 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.exeptions.MatchIdNotFoundException; -import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TeamIdNotFoundException; -import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException; +import hdm.mi.sthbackend.dto.TournamentDTO; +import hdm.mi.sthbackend.exeptions.*; +import hdm.mi.sthbackend.mapper.ModelToDTOMapper; import hdm.mi.sthbackend.model.Match; import hdm.mi.sthbackend.model.Player; import hdm.mi.sthbackend.model.Team; @@ -14,9 +14,11 @@ 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; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; @@ -25,14 +27,17 @@ import java.util.*; @AllArgsConstructor public class TournamentService { - private final static Logger log = LogManager.getLogger(TournamentService.class); + private final Logger log = LogManager.getLogger(TournamentService.class); ITournamentRepository tournamentRepository; IPlayerRepository playerRepository; ITeamRepository teamRepository; IMatchRepository matchRepository; - public Player addPlayerToTeam(UUID teamId, + @Autowired + ModelToDTOMapper mapper; + + public PlayerDTO addPlayerToTeam(UUID teamId, String playerName) throws TeamIdNotFoundException { Team team = teamRepository.findById(teamId) .orElseThrow(() -> new TeamIdNotFoundException(teamId)); @@ -44,14 +49,14 @@ public class TournamentService { playerRepository.insert(newPlayer); teamRepository.save(team); log.debug("Player " + newPlayer.getPlayerId() + " added to Team " + teamId); - return newPlayer; + return mapper.mapToPlayerDTO(newPlayer); } public PlayerDTO findPlayerById(UUID playerId) throws PlayerIdNotFoundException { Player player = playerRepository.findById(playerId) .orElseThrow(() -> new PlayerIdNotFoundException(playerId)); - return new PlayerDTO(player.getPlayerId(), player.getName()); + return mapper.mapToPlayerDTO(player); } /* @@ -77,7 +82,7 @@ public class TournamentService { teamRepository.save(team); log.debug("Player " + playerId + " removed from Team " + teamId); - return new PlayerDTO(playerToDelete.getPlayerId(), playerToDelete.getName()); + return mapper.mapToPlayerDTO(playerToDelete); } /* @@ -104,10 +109,10 @@ public class TournamentService { forEach(pId -> playerRepository.findById(pId) .ifPresent(p -> teamMembers.put(p.getPlayerId(), new PlayerDTO(p.getPlayerId(), p.getName())))); - return new TeamDTO(team.getId(), team.getTeamName(), teamMembers); + return mapper.mapToTeamDTO(team); } - public Team createAndAddTeamToTournament(UUID tournamentId, String teamName) throws TournamentIdNotFoundException { + public TeamDTO createAndAddTeamToTournament(UUID tournamentId, String teamName) throws TournamentIdNotFoundException { Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); @@ -118,7 +123,7 @@ public class TournamentService { teamRepository.insert(newTeam); tournamentRepository.save(tournament); - return newTeam; + return mapper.mapToTeamDTO(newTeam); } public UUID deleteAndRemoveTeamFromTournament(UUID tournamentId, @@ -140,54 +145,92 @@ public class TournamentService { return teamId; } - public Tournament createTournament(String tournamentName) { + public TournamentDTO createTournament(String tournamentName) { Tournament tournament = new Tournament(UUID.randomUUID(), tournamentName, new ArrayList<>(), new ArrayList<>()); tournamentRepository.insert(tournament); log.debug("created Tournament " + tournament.getTournamentId()); - return tournament; + return mapper.mapToTournamentDTO(tournament); } - public UUID determineWinner (UUID tournamentId, UUID matchId) throws TournamentIdNotFoundException, MatchIdNotFoundException{ - - Tournament tournament = tournamentRepository.findById(tournamentId) - .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); - - Match match = tournament.getMatches().stream() - .filter(m -> m.getMatchId().equals(matchId)) - .findFirst() - .orElseThrow(() -> new MatchIdNotFoundException(matchId)); + public UUID determineWinner (UUID matchId) throws MatchIdNotFoundException, WinnerNotDeterminedException { + Match match = matchRepository.findById(matchId).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)); match.setWinnerTeamId(winnerTeamId); - tournamentRepository.save(tournament); - log.debug("The Winner " + winnerTeamId + " is determined for Match " + matchId + " in Tournament " + tournamentId); + matchRepository.save(match); + log.debug("The Winner " + winnerTeamId + " is determined for Match " + matchId); 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 ); + return mapper.mapToMatchDTO(match); + } + + + 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)) { + throw new TeamIdNotFoundException(teamId); + } + match.getTeamScores().put(teamId, newScore); + matchRepository.save(match); + log.debug("Score of Team " + teamId + " updated to " + newScore); + return mapper.mapToMatchDTO(match); + } + + + 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 mapper.mapToTeamDTO(team); + } + + public UUID updateTournamentName(UUID tournamentId, String newTournamentName)throws TournamentIdNotFoundException{ Tournament tournament = tournamentRepository.findById(tournamentId) .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); - Match match = tournament.getMatches().stream() - .filter(m -> m.getMatchId().equals(matchId)) - .findFirst() - .orElseThrow(() -> new MatchIdNotFoundException(matchId)); + tournament.setTournamentName(newTournamentName); + tournamentRepository.save(tournament); + log.debug("Tournament Name for TournamentID " + tournamentId + " updated to " + newTournamentName); + return tournamentId; + } + public TournamentDTO getTournament(UUID tournamentId) throws TournamentIdNotFoundException { + Tournament tournament = tournamentRepository.findById(tournamentId) + .orElseThrow(() -> new TournamentIdNotFoundException(tournamentId)); + log.debug(tournament + "is found"); + return mapper.mapToTournamentDTO(tournament); + } - match.getTeamScores().put(teamId,score); - tournamentRepository.save(tournament); - log.debug("Team " + teamId + " assign to Match " + matchId + " in Tournament " + tournamentId); + 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); } /* Weitere Methoden: - Gewinner bestimmen, defineWinner() - Teams Matches zuordnen, - + UpdateTeamScore Marius + Tunier beenden + GetTournament Leon + DeleteTournament Leon + User Mattis */ 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; + +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamName.java b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamName.java new file mode 100644 index 0000000000000000000000000000000000000000..46f97d8aa5bd9763dab456d0cbf3ac757ab6688c --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TeamName.java @@ -0,0 +1,8 @@ +package hdm.mi.sthbackend.types; + +import lombok.Getter; + +@Getter +public class TeamName { + private String name; +} diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/types/TournamentName.java b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TournamentName.java new file mode 100644 index 0000000000000000000000000000000000000000..604b905da88e8b59498d67a37dcb844445386747 --- /dev/null +++ b/sth-backend/src/main/java/hdm/mi/sthbackend/types/TournamentName.java @@ -0,0 +1,8 @@ +package hdm.mi.sthbackend.types; + +import lombok.Getter; + +@Getter +public class TournamentName { + private String name; +}