-
Notifications
You must be signed in to change notification settings - Fork 14
[Fix] Improve match, round, referee, CompetitioTable entity adding lambok notation #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4890aae
dc6f0a0
8be15c3
08b8d3e
1a14d3e
ca7c8d2
71038e6
19e49b2
678083a
15c352b
e8bc4ad
653d1b0
266e371
5b33af1
a562ade
d7ae4c8
00e3fe6
21b8915
62fc1e3
956367a
e9949d9
c36aa63
be1b573
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,88 +9,105 @@ | |
| import jakarta.persistence.OneToMany; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Entity | ||
| @Table(name = "competition_tables") | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) | ||
| public class CompetitionTable extends UriEntity<String> { | ||
|
|
||
| @Id | ||
| @EqualsAndHashCode.Include | ||
| private String id; | ||
|
|
||
| @OneToMany(mappedBy = "competitionTable", cascade = CascadeType.ALL) | ||
| @OneToMany(mappedBy = "competitionTable", cascade = {CascadeType.PERSIST, CascadeType.MERGE}) | ||
| @JsonManagedReference("table-matches") | ||
| @Setter(lombok.AccessLevel.NONE) | ||
| private List<Match> matches = new ArrayList<>(); | ||
|
|
||
| @OneToMany(mappedBy = "supervisesTable") | ||
| @Size(max = 3, message = "A table can have a maximum of 3 referees") | ||
| @JsonManagedReference("table-referees") | ||
| @Setter(lombok.AccessLevel.NONE) | ||
| private List<Referee> referees = new ArrayList<>(); | ||
|
|
||
|
|
||
| @Override | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(String id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public List<Match> getMatches() { | ||
| return matches; | ||
| } | ||
|
|
||
| public void setMatches(List<Match> matches) { | ||
| new ArrayList<>(this.matches).forEach(this::removeMatch); | ||
| if (matches != null) { | ||
| matches.forEach(this::addMatch); | ||
| } | ||
| } | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public List<Referee> getReferees() { | ||
| return referees; | ||
| } | ||
| public void addMatch(Match match) { | ||
| if (match == null) { | ||
| return; | ||
| } | ||
|
|
||
| public void setReferees(List<Referee> referees) { | ||
| new ArrayList<>(this.referees).forEach(this::removeReferee); | ||
| if (referees != null) { | ||
| referees.forEach(this::addReferee); | ||
| if (this.matches.stream().anyMatch(m -> m == match)) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| public void addMatch(Match match) { | ||
| CompetitionTable previousTable = match.getCompetitionTable(); | ||
| if (previousTable != null && previousTable != this) { | ||
| previousTable.removeMatch(match); | ||
| } | ||
| if (!matches.contains(match)) { | ||
| matches.add(match); | ||
| previousTable.getMatches().removeIf(m -> m == match); | ||
| } | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| this.matches.add(match); | ||
| match.setCompetitionTable(this); | ||
|
Comment on lines
+52
to
62
|
||
| } | ||
|
Comment on lines
+47
to
63
|
||
|
|
||
| public void removeMatch(Match match) { | ||
| matches.remove(match); | ||
| match.setCompetitionTable(null); | ||
| if (match == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.matches.removeIf(m -> m == match)) { | ||
| match.setCompetitionTable(null); | ||
| } | ||
|
Comment on lines
65
to
+72
|
||
| } | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public void setReferees(List<Referee> referees) { | ||
| new ArrayList<>(this.referees).forEach(this::removeReferee); | ||
| if (referees != null) { | ||
| referees.forEach(this::addReferee); | ||
| } | ||
| } | ||
|
Comment on lines
+75
to
+80
|
||
|
|
||
| public void addReferee(Referee referee) { | ||
| CompetitionTable previousTable = referee.getSupervisesTable(); | ||
| if (previousTable != null && previousTable != this) { | ||
| previousTable.removeReferee(referee); | ||
| if (referee == null) { | ||
| return; | ||
| } | ||
| if (referees.contains(referee)) { | ||
|
|
||
| if (this.referees.stream().anyMatch(r -> r == referee)) { | ||
| return; | ||
| } | ||
|
Comment on lines
+87
to
89
|
||
| if (referees.size() >= 3) { | ||
|
|
||
| if (this.referees.size() >= 3) { | ||
| throw new IllegalStateException("A table can have a maximum of 3 referees"); | ||
| } | ||
| referees.add(referee); | ||
|
|
||
| CompetitionTable previousTable = referee.getSupervisesTable(); | ||
| if (previousTable != null && previousTable != this) { | ||
| previousTable.getReferees().removeIf(r -> r == referee); | ||
| } | ||
|
Comment on lines
+96
to
+98
|
||
|
|
||
| this.referees.add(referee); | ||
| referee.setSupervisesTable(this); | ||
|
Comment on lines
+87
to
101
|
||
| } | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+100
to
102
|
||
|
|
||
| public void removeReferee(Referee referee) { | ||
| referees.remove(referee); | ||
| referee.setSupervisesTable(null); | ||
| if (referee == null) { | ||
| return; | ||
| } | ||
|
|
||
| if (this.referees.removeIf(r -> r == referee)) { | ||
| referee.setSupervisesTable(null); | ||
| } | ||
|
Comment on lines
104
to
+111
|
||
| } | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,28 +13,33 @@ | |
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "matches") | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = false, onlyExplicitlyIncluded = true) | ||
| public class Match extends UriEntity<Long> { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
|
Comment on lines
+26
to
30
|
||
| @EqualsAndHashCode.Include | ||
| private Long id; | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+23
to
32
|
||
|
|
||
| private LocalTime startTime; | ||
|
|
||
| private LocalTime endTime; | ||
|
|
||
| @JsonBackReference("round-matches") | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "round_id") | ||
| private Round round; | ||
| @Enumerated(EnumType.STRING) | ||
| private MatchState state = MatchState.SCHEDULED; | ||
|
|
||
| @JsonBackReference("table-matches") | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "table_id") | ||
| private CompetitionTable competitionTable; | ||
| @JoinColumn(name = "referee_id") | ||
| private Referee referee; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "team_a_id") | ||
|
|
@@ -47,84 +52,12 @@ public class Match extends UriEntity<Long> { | |
| private Team teamB; | ||
xji650 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "referee_id") | ||
| private Referee referee; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private MatchState state = MatchState.SCHEDULED; | ||
|
|
||
| public Match() {} | ||
|
|
||
| @Override | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public LocalTime getStartTime() { | ||
| return startTime; | ||
| } | ||
|
|
||
| public void setStartTime(LocalTime startTime) { | ||
| this.startTime = startTime; | ||
| } | ||
|
|
||
| public LocalTime getEndTime() { | ||
| return endTime; | ||
| } | ||
|
|
||
| public void setEndTime(LocalTime endTime) { | ||
| this.endTime = endTime; | ||
| } | ||
|
|
||
| public Round getRound() { | ||
| return round; | ||
| } | ||
|
|
||
| public void setRound(Round round) { | ||
| this.round = round; | ||
| } | ||
|
|
||
| public CompetitionTable getCompetitionTable() { | ||
| return competitionTable; | ||
| } | ||
|
|
||
| public void setCompetitionTable(CompetitionTable competitionTable) { | ||
| this.competitionTable = competitionTable; | ||
| } | ||
|
|
||
| public Team getTeamA() { | ||
| return teamA; | ||
| } | ||
|
|
||
| public void setTeamA(Team teamA) { | ||
| this.teamA = teamA; | ||
| } | ||
|
|
||
| public Team getTeamB() { | ||
| return teamB; | ||
| } | ||
|
|
||
| public void setTeamB(Team teamB) { | ||
| this.teamB = teamB; | ||
| } | ||
|
|
||
| public Referee getReferee() { | ||
| return referee; | ||
| } | ||
|
|
||
| public void setReferee(Referee referee) { | ||
| this.referee = referee; | ||
| } | ||
|
|
||
| public MatchState getState() { | ||
| return state; | ||
| } | ||
| @JoinColumn(name = "round_id") | ||
| @JsonBackReference("round-matches") | ||
| private Round round; | ||
|
|
||
| public void setState(MatchState state) { | ||
| this.state = state; | ||
| } | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "table_id") | ||
| @JsonBackReference("table-matches") | ||
| private CompetitionTable competitionTable; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.