From bb516fc16e4222fe1cf6faf3ff899770acad01ac Mon Sep 17 00:00:00 2001 From: msiStefan <ss576@hdm-stuttgart.de> Date: Thu, 28 Dec 2023 13:52:05 +0100 Subject: [PATCH] 28.12.2023 - added assignTeamToMatch Methode zu TournamentService (Marius Stefan) #24 --- .../sthbackend/service/TournamentService.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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 de74213..a0540c5 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 @@ -5,19 +5,14 @@ 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.model.Match; -import hdm.mi.sthbackend.model.Player; -import hdm.mi.sthbackend.model.Team; -import hdm.mi.sthbackend.model.Tournament; +import hdm.mi.sthbackend.model.*; import hdm.mi.sthbackend.repository.ITournamentRepository; import hdm.mi.sthbackend.repository.MongoManager; import lombok.AllArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.springframework.data.mongodb.core.aggregation.VariableOperators; import org.springframework.stereotype.Service; -import javax.swing.text.html.parser.Entity; import java.util.*; @Service @@ -156,6 +151,21 @@ public class TournamentService { return winnerTeamId; } + public void assignTeamToMatch(UUID tournamentId, UUID matchId, UUID teamId, int score) 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)); + + + match.getTeamScores().put(teamId,score); + tournamentRepository.save(tournament); + log.debug("Team " + teamId + " assign to Match " + matchId + " in Tournament " + tournamentId); + } + /* Weitere Methoden: Gewinner bestimmen, defineWinner() -- GitLab