Skip to content
Snippets Groups Projects
Commit 9baecce2 authored by Jonas's avatar Jonas
Browse files

26.12.2023 - refactored classes Team and Match

parent 9a0b8b28
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
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;
}
......@@ -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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment