mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2025-12-22 14:41:57 +00:00
add tracking of passed teams and their times
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package de.pnreichmuth.timekeep_backend.entities;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamExistsException;
|
||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@@ -21,9 +21,31 @@ public class Station {
|
||||
private String location;
|
||||
private String passwordHash;
|
||||
|
||||
@ManyToMany(cascade = {CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
|
||||
@JoinTable(name="team_passed_stations")
|
||||
private Set<Team> passedTeams;
|
||||
|
||||
@ElementCollection
|
||||
private Map<Team, LocalDate> passingTimes;
|
||||
|
||||
public Station(String name, String location){
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.passwordHash = null;
|
||||
this.passedTeams = new HashSet<>(1);
|
||||
this.passingTimes = new HashMap<>(1);
|
||||
}
|
||||
|
||||
public void teamPassed(Team team){
|
||||
if(!passedTeams.add(team)){
|
||||
throw new TeamExistsException("Team %s was already seen at this Station: %s".formatted(team.getTeamName(), this.location), team);
|
||||
}
|
||||
passingTimes.put(team, LocalDate.now());
|
||||
}
|
||||
|
||||
public void removePassedTeam(Team team){
|
||||
if (!passedTeams.contains(team)) throw new TeamNotFoundException("Team %s was never seen at this station: %s".formatted(team.getTeamName(), this.location));
|
||||
passedTeams.remove(team);
|
||||
passingTimes.remove(team);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user