From d8272a696d645cc1a9fa5c429587326f87167e9e Mon Sep 17 00:00:00 2001
From: andriluccahannes <lb214@hdm-stuttgart.de>
Date: Tue, 16 Jan 2024 13:09:24 +0100
Subject: [PATCH] =?UTF-8?q?16.01.2024=20-=20Jonas=20has=20to=20fix=20Tourn?=
 =?UTF-8?q?amentService=20because=20he=20is=20such=20a=20flei=C3=9Figer=20?=
 =?UTF-8?q?Junge?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../src/main/java/hdm/mi/sthbackend/model/Team.java |  3 +--
 .../java/hdm/mi/sthbackend/model/Tournament.java    |  6 ++----
 .../mi/sthbackend/repository/IMatchRepository.java  |  9 ---------
 .../mi/sthbackend/repository/IPlayerRepository.java | 13 -------------
 .../mi/sthbackend/repository/ITeamRepository.java   |  9 ---------
 .../mi/sthbackend/service/TournamentService.java    | 13 ++++++-------
 6 files changed, 9 insertions(+), 44 deletions(-)
 delete mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/repository/IMatchRepository.java
 delete mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/repository/IPlayerRepository.java
 delete mode 100644 sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITeamRepository.java

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 88d9e0b..8d4e46a 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
@@ -11,10 +11,9 @@ import java.util.List;
 import java.util.UUID;
 
 @Getter
-@Document("Team")
 @AllArgsConstructor
 public class Team {
-    @Id
+
     private final UUID teamId;
     @Setter
     private String teamName;
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 203ff94..2ec62f3 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
@@ -23,7 +23,7 @@ public class Tournament implements ITournament{
     private String tournamentName;
     @Setter
     private List<BracketRound> bracket;
-    private List<Team> teams;
+    private Map<UUID, Team> teams;
     private List<UUID> users;
 
 
@@ -32,9 +32,7 @@ public class Tournament implements ITournament{
         this.tournamentId = UUID.randomUUID();
         this.tournamentName = tournamentName;
         this.bracket = new ArrayList<>();
-        this.teams = teamNames.stream().map( Team::new ).toList();
+        this.teams = teamNames.stream().map( Team::new ).collect(Collectors.toMap(Team::getTeamId, team -> team ));
     }
 
-    public Tournament(){};
-
 }
diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IMatchRepository.java b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IMatchRepository.java
deleted file mode 100644
index 9c7b236..0000000
--- a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IMatchRepository.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package hdm.mi.sthbackend.repository;
-
-import hdm.mi.sthbackend.model.Match;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.UUID;
-
-public interface IMatchRepository extends MongoRepository<Match, UUID> {
-}
diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IPlayerRepository.java b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IPlayerRepository.java
deleted file mode 100644
index def7824..0000000
--- a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/IPlayerRepository.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package hdm.mi.sthbackend.repository;
-
-import hdm.mi.sthbackend.model.Player;
-import hdm.mi.sthbackend.model.Tournament;
-import org.springframework.data.mongodb.repository.MongoRepository;
-import org.springframework.stereotype.Repository;
-
-import java.util.UUID;
-
-@Repository
-public interface IPlayerRepository extends MongoRepository<Player, UUID> {
-
-}
diff --git a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITeamRepository.java b/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITeamRepository.java
deleted file mode 100644
index e2bb9c3..0000000
--- a/sth-backend/src/main/java/hdm/mi/sthbackend/repository/ITeamRepository.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package hdm.mi.sthbackend.repository;
-
-import hdm.mi.sthbackend.model.Team;
-import org.springframework.data.mongodb.repository.MongoRepository;
-
-import java.util.UUID;
-
-public interface ITeamRepository extends MongoRepository<Team, UUID> {
-}
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 dfa77fe..8b69b43 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
@@ -25,17 +25,16 @@ public class TournamentService {
     private final Logger log = LogManager.getLogger(TournamentService.class);
 
     ITournamentRepository tournamentRepository;
-    IPlayerRepository playerRepository;
-    ITeamRepository teamRepository;
-    IMatchRepository matchRepository;
 
     @Autowired
     ModelToDTOMapper mapper;
 
-    public PlayerDTO addPlayerToTeam(UUID teamId,
-                                  String playerName) throws TeamIdNotFoundException {
-        Team team = teamRepository.findById(teamId)
-                .orElseThrow(() -> new TeamIdNotFoundException(teamId));
+    public PlayerDTO addPlayerToTeam(UUID tournamentId, UUID teamId,
+                                  String playerName) throws TournamentIdNotFoundException, TeamIdNotFoundException {
+        Tournament tournament = tournamentRepository.findById(tournamentId)
+                .orElseThrow(() -> new TournamentIdNotFoundException( tournamentId));
+
+        Team team = Optional.ofNullable( tournament.getTeams().get( teamId )).orElseThrow(() -> new TeamIdNotFoundException(teamId)) ;
 
         Player newPlayer = new Player(UUID.randomUUID(), playerName);
         team.getTeamMembers()
-- 
GitLab