From 9baecce2f2bdab42b3305daf76844ec04062c423 Mon Sep 17 00:00:00 2001
From: Jonas <jonas.fischer14@gmx.de>
Date: Tue, 26 Dec 2023 19:58:31 +0100
Subject: [PATCH] 26.12.2023 - refactored classes Team and Match

---
 .../java/hdm/mi/sthbackend/model/Match.java   | 32 +++----------------
 .../java/hdm/mi/sthbackend/model/Team.java    |  3 +-
 2 files changed, 7 insertions(+), 28 deletions(-)

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 fba9a67..dbb97aa 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
@@ -1,17 +1,14 @@
 package hdm.mi.sthbackend.model;
 
-import hdm.mi.sthbackend.exeptions.TeamMatchScoreIdNotFoundException;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
-import lombok.RequiredArgsConstructor;
 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.List;
-import java.util.Objects;
+import java.util.Map;
 import java.util.UUID;
 
 @Getter
@@ -22,34 +19,15 @@ public class Match {
 
     @Id
     private UUID matchId;
-    private List<TeamMatchScore> teamScores;
 
-    // todo problem mit doppelten gespeicherten daten? Eher nur UUID nutzen für winner
+    private Map<UUID, Number> teamScores;
+
     @Setter
-    private Team winner;
+    private UUID winnerTeamId;
 
     @Setter
     private String comment;
 
     @Setter
-    private Match nextMatch;
-
-
-    public void removeTeam(UUID teamMatchScoreId) throws Exception {
-        TeamMatchScore team = teamScores.stream().filter(t -> t.getTeamMatchScoreId().equals(teamMatchScoreId)).findFirst().orElse(null);
-        log.debug("removeTeam: " + team);
-        if (team == null) {
-            throw new TeamMatchScoreIdNotFoundException(String.format("TeamMatchScoreID %s was not found", teamMatchScoreId));
-        }
-        teamScores.remove(team);
-    }
-
-    public void removeTeam(TeamMatchScore team) {
-        teamScores.remove(team);
-    }
-
-    public TeamMatchScore[] getAllTeams() {
-        return (TeamMatchScore[]) teamScores.stream().filter(Objects::nonNull).toArray();
-    }
-
+    private UUID nextMatchId;
 }
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 f03a287..a6a8244 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
@@ -6,6 +6,7 @@ import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
 
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 @Getter
@@ -16,5 +17,5 @@ public class Team {
     private final UUID id;
 
     private final String teamName;
-    private final List<Player> teamMembers;
+    private final Map<UUID, Player> teamMembers;
 }
-- 
GitLab