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

06.12.2023 - add methods to models #4

parent 8cc07039
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
Showing
with 151 additions and 11 deletions
9
README.md,8\e\8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d
I
tournament-factory-adr.md,8\1\81d8eb2bc5a911b258c49bed79926844ea3988f0
C
docker-compose.yaml,e\f\ef8def03dc8f162799089e9b5f4321201c8810d5
F
sth-backend/Dockerfile,a\d\ad9815cb514700b7f513e4aad039536e258c58d9
@
sth-backend/mvnw,f\7\f764c0a37a5c9f7a04bea4edf778d74fc41a085c
C
sth-backend/pom.xml,f\f\ffa88f39108e02aca02fbfcfdefda86d60005743
m
=sth-backend/src/main/java/hdm/mi/sthbackend/model/IMatch.java,1\5\15d493c652d20750608adb0a33ec5d3ad17ece3d
r
Bsth-backend/src/main/java/hdm/mi/sthbackend/model/ITournament.java,d\4\d4d373a247368212c60cc99595abbf323611ed8f
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="496df6ed-8d28-4ba0-bd76-20bf08cf48f0" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
package hdm.mi.sthbackend.exeptions;
public class PlayerIdNotFoundException extends Exception {
public PlayerIdNotFoundException (String playerId) {
super(String.format("PlayerId %s not found", playerId));
}
}
package hdm.mi.sthbackend.exeptions;
public class TeamMatchScoreIdNotFoundException extends Exception{
public TeamMatchScoreIdNotFoundException(String message) {
super(message);
}
}
package hdm.mi.sthbackend.model; package hdm.mi.sthbackend.model;
import org.hibernate.id.uuid.UuidGenerator; import hdm.mi.sthbackend.exeptions.TeamMatchScoreIdNotFoundException;
import lombok.Getter;
import lombok.Setter;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class Match { public class Match {
private String matchId; @Getter
private List<TeamMatchScore> teams; private final UUID matchId;
private final List<TeamMatchScore> teams;
@Getter
@Setter
private Team winner; private Team winner;
@Getter
@Setter
private String comment; private String comment;
@Getter
@Setter
private Match nextMatch; private Match nextMatch;
public Match(String matchId, List<TeamMatchScore> teams, Team winner, String comment, Match nextMatch) { public Match(List<TeamMatchScore> teams, Team winner, String comment, Match nextMatch) {
this.matchId = matchId; this.matchId = UUID.randomUUID();
this.teams = teams; this.teams = teams;
this.winner = winner; this.winner = winner;
this.comment = comment; this.comment = comment;
this.nextMatch = nextMatch; this.nextMatch = nextMatch;
} }
public Match(String matchId, List<TeamMatchScore> teams, Team winner, Match nextMatch) { public Match(List<TeamMatchScore> teams, Team winner, Match nextMatch) {
this(matchId, teams, winner, "", nextMatch); this(teams, winner, "", nextMatch);
} }
public void addTeam(Team team) { public void addTeam(Team team) {
teams.add(new TeamMatchScore( team, 0)); teams.add(new TeamMatchScore(team, 0));
} }
public void removeTeam(UUID teamMatchScoreId) throws Exception {
TeamMatchScore team = teams.stream().filter(t -> t.getTeamMatchScoreId().equals(teamMatchScoreId)).findFirst().orElse(null);
if (team == null) {
throw new TeamMatchScoreIdNotFoundException(String.format("TeamMatchScoreID %s was not found", teamMatchScoreId));
}
teams.remove(team);
}
public void removeTeam(TeamMatchScore team) {
teams.remove(team);
}
public TeamMatchScore[] getAllTeams() {
return (TeamMatchScore[]) teams.stream().filter(Objects::nonNull).toArray();
}
} }
package hdm.mi.sthbackend.model; package hdm.mi.sthbackend.model;
import hdm.mi.sthbackend.exeptions.PlayerIdNotFoundException;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
public class Team { public class Team {
private String teamId; @Getter
private List<Player> teamMembers; private final UUID teamId;
private final List<Player> teamMembers;
public Team() {
this.teamId = UUID.randomUUID();
this.teamMembers = new ArrayList<>();
}
public void addPlayer(Player player) {
this.teamMembers.add(player);
}
public void removePlayer(UUID playerId) throws PlayerIdNotFoundException {
Player player = this.teamMembers.stream().filter(p -> p.getPlayerId().equals(playerId)).findFirst().orElse(null);
if (player == null) {
throw new PlayerIdNotFoundException(playerId.toString());
}
teamMembers.remove(player);
}
public void removePlayer(Player player) {
teamMembers.remove(player);
}
} }
package hdm.mi.sthbackend.model; package hdm.mi.sthbackend.model;
import lombok.Getter;
import java.util.UUID; import java.util.UUID;
public class TeamMatchScore { public class TeamMatchScore {
private UUID teamMatchScoreId; @Getter
private final UUID teamMatchScoreId;
private Team team; private Team team;
private int score; private int score;
......
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sth-frontend.iml" filepath="$PROJECT_DIR$/.idea/sth-frontend.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
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