Compare commits

...

8 Commits

Author SHA1 Message Date
Michel ten Voorde
1a1a0e373f Update counter
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-11-06 16:39:00 +01:00
Michel ten Voorde
d5df8f5d32 Cleanup
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-11-03 14:32:13 +01:00
Michel ten Voorde
1df0ebee5c Corrected cascading
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 17:22:16 +01:00
Michel ten Voorde
ce9f10acb9 Add logging
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 16:37:50 +01:00
Michel ten Voorde
001a83e75a Add logging
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 16:33:36 +01:00
Michel ten Voorde
277bcadb5d Add logging
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 15:55:57 +01:00
Michel ten Voorde
b836112ba5 Add logging
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 15:48:04 +01:00
Michel ten Voorde
180d431f8d Fix when no rounds
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-27 14:41:10 +01:00
6 changed files with 200 additions and 156 deletions

View File

@@ -161,8 +161,10 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId,
@RequestParam("court") Long court, @RequestParam("counter") Long counter) {
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestParam("court") Long court,
@RequestParam("counter") Long counter) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
@@ -176,14 +178,18 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}")
public ResponseEntity<TournamentDto> saveResult(@PathVariable Long tournamentId, @PathVariable Long matchId, @RequestBody ResultDto resultDto) {
public ResponseEntity<TournamentDto> saveResult(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestBody ResultDto resultDto) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto)));
}
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/paid/{paid}")
public ResponseEntity<Void> updatePaid(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Boolean paid) {
public ResponseEntity<Void> updatePaid(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@PathVariable Boolean paid) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePaid(tournament, playerId, paid);
@@ -192,7 +198,9 @@ public class TournamentController {
}
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/present/{present}")
public ResponseEntity<Void> updatePresent(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Boolean present) {
public ResponseEntity<Void> updatePresent(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@PathVariable Boolean present) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePresent(tournament, playerId, present);
@@ -201,9 +209,21 @@ public class TournamentController {
}
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/substitutions")
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId, @PathVariable Long playerId, @RequestBody TournamentPlayerSubstitutionDto[] substitutions) {
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId,
@PathVariable Long playerId,
@RequestBody TournamentPlayerSubstitutionDto[] substitutions) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.playerSubstitutions(tournament, playerId, substitutions)));
}
@PatchMapping("/tournaments/{tournamentId}/matches/{matchId}/update")
public ResponseEntity<TournamentDto> updateCounter(@PathVariable Long tournamentId,
@PathVariable Long matchId,
@RequestParam("counter") Long counter) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.updateCounter(tournament, matchId, counter)));
}
}

View File

@@ -33,12 +33,12 @@ public class Group extends AbstractEntity {
@OrderBy("name")
private List<Round> rounds;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
@JoinTable(
name = "eventgroup_teams",
joinColumns = @JoinColumn(name = "group_id"),
inverseJoinColumns = @JoinColumn(name = "teams_id")
)
private List<Team> teams;
private List<Team> teams = new ArrayList<>();
}

View File

@@ -2,6 +2,7 @@ package nl.connectedit.swiss.domain.entity;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -19,7 +20,7 @@ public class Team extends AbstractEntity {
private Long id;
@ManyToMany(mappedBy = "teams", fetch = FetchType.LAZY)
private List<Group> groups;
private List<Group> groups = new ArrayList<>();
@ManyToOne
private Player player1;

View File

@@ -96,6 +96,7 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
for (var event : tournament.getEvents()) {
if (event.getGroups() != null) {
for (var group : event.getGroups()) {
if (group.getRounds() != null) {
for (var round : group.getRounds()) {
for (var match : round.getMatches()) {
if (match.getStatus() == Status.IN_PROGRESS && match.getCounter() != null) {
@@ -109,6 +110,7 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
}
}
}
}
return playersCounting;
}
@@ -118,6 +120,7 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
for (var event : tournament.getEvents()) {
if (event.getGroups() != null) {
for (var group : event.getGroups()) {
if (group.getRounds() != null) {
for (var round : group.getRounds()) {
for (var match : round.getMatches()) {
if (match.getStatus() == Status.IN_PROGRESS) {
@@ -128,6 +131,7 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
}
}
}
}
return playersPlaying;
}

View File

@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import nl.connectedit.swiss.domain.EventType;
import nl.connectedit.swiss.domain.Status;
import nl.connectedit.swiss.domain.TournamentStatus;
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@Log
public class TournamentDivideService {
private final TournamentValidationService tournamentValidationService;
@@ -72,7 +74,7 @@ public class TournamentDivideService {
private List<Registration> groupRegistrations(List<Registration> registrations) {
var groupedRegistrations = new ArrayList<Registration>();
nextRegistration:
nextRegistration:
for (var registration : registrations) {
for (var groupedRegistration : groupedRegistrations) {
if (Objects.equals(groupedRegistration.getPartner(), registration.getPlayer())) {
@@ -91,13 +93,16 @@ nextRegistration:
group.setStatus(Status.IN_PROGRESS);
group.setTeams(new ArrayList<>());
for (var registration : registrations) {
group.getTeams().add(getTeam(registration, group));
// group.getTeams().add(getTeam(registration, group));
addTeamToGroup(registration, group);
}
return group;
}
private List<Group> getGroups(List<Registration> orgRegistrations, EventType type) {
var groups = new ArrayList<Group>();
var registrations = new ArrayList<>(orgRegistrations);
var group1 = new Group();
@@ -140,18 +145,28 @@ nextRegistration:
group2.getTeams().removeLast();
}
return List.of(group1, group2);
groups.add(group1);
groups.add(group2);
return groups;
}
private Team getTeam(Registration registration, Group group) {
var team = new Team();
team.setPlayer1(registration.getPlayer());
team.setPlayer2(registration.getPartner());
team.setGroups(List.of(group));
team.getGroups().add(group);
return team;
}
private void addTeamToGroup(Registration registration, Group group) {
var team = new Team();
team.setPlayer1(registration.getPlayer());
team.setPlayer2(registration.getPartner());
team.getGroups().add(group);
group.getTeams().add(team);
}
public Tournament clear(Tournament tournament) {
for (var event : tournament.getEvents()) {
event.getGroups().clear();

View File

@@ -168,22 +168,12 @@ public class TournamentPlayService {
round.setMatches(matches);
printRound(round, standings);
group.getRounds().add(round);
tournamentRepository.save(tournament);
return tournament;
}
private void printRound(Round round, List<StandingsEntry> standings) {
for (var match: round.getMatches()) {
log.info("%s - %s".formatted(
String.valueOf(standings.stream().filter(entry -> entry.getTeam().equals(match.getTeam1())).map(StandingsEntry::getPosition).findFirst().get()),
String.valueOf(standings.stream().filter(entry -> entry.getTeam().equals(match.getTeam2())).map(StandingsEntry::getPosition).findFirst().get())));
}
}
public Tournament playerSubstitutions(Tournament tournament, Long playerId, TournamentPlayerSubstitutionDto[] substitutions) {
var tournamentPlayer = getTournamentPlayer(tournament, playerId);
@@ -230,6 +220,21 @@ public class TournamentPlayService {
return null;
}
public Tournament updateCounter(Tournament tournament, Long matchId, Long counter) {
var match = getMatch(tournament, matchId);
var currentlyCountingPlayer = getTournamentPlayer(tournament, match.getCounter().getId());
currentlyCountingPlayer.setCounting(false);
var newCountingPlayer = getTournamentPlayer(tournament, counter);
newCountingPlayer.setCounting(true);
match.setCounter(newCountingPlayer.getPlayer());
tournamentRepository.save(tournament);
return tournament;
}
private static class ConflictInDrawException extends RuntimeException {}
@@ -244,7 +249,6 @@ public class TournamentPlayService {
if (!findPreviousMatchOccurence(newMatch.getTeam1(), remainingTeams.get(opponentIndex), group)) {
newMatch.setTeam2(remainingTeams.get(opponentIndex));
} else {
log.info("Wedstrijd %s - %s kwam al eerder voor.".formatted(newMatch.getTeam1().toString(), remainingTeams.get(opponentIndex).toString()));
continue;
}
var newRemainingTeams = getRemainingTeams(remainingTeams, opponentIndex);