Compare commits

...

11 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
cca133d67c Fix when no groups
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-10-25 15:27:19 +02:00
1385dc56a1 Revert "Hibernate warning fixes"
This reverts commit dd653cb525.
2025-10-25 15:22:03 +02:00
1d0cc270e3 Fix when no substitutions 2025-10-25 15:22:00 +02:00
14 changed files with 218 additions and 171 deletions

View File

@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version> <version>3.5.6</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>nl.connected-it</groupId> <groupId>nl.connected-it</groupId>
@@ -50,7 +50,10 @@
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

View File

@@ -26,184 +26,204 @@ import java.util.Objects;
@RequiredArgsConstructor @RequiredArgsConstructor
public class TournamentController { public class TournamentController {
private final TournamentService tournamentService; private final TournamentService tournamentService;
private final TournamentMapper tournamentMapper; private final TournamentMapper tournamentMapper;
private final TournamentValidationService tournamentValidationService; private final TournamentValidationService tournamentValidationService;
private final TournamentValidationMapper tournamentValidationMapper; private final TournamentValidationMapper tournamentValidationMapper;
private final TournamentDivideService tournamentDivideService; private final TournamentDivideService tournamentDivideService;
private final TournamentDrawService tournamentDrawService; private final TournamentDrawService tournamentDrawService;
private final TournamentPlayService tournamentPlayService; private final TournamentPlayService tournamentPlayService;
@GetMapping("/tournaments") @GetMapping("/tournaments")
public ResponseEntity<List<TournamentDto>> getTournaments(@RequestParam(value = "status", required = false) TournamentStatus status) { public ResponseEntity<List<TournamentDto>> getTournaments(@RequestParam(value = "status", required = false) TournamentStatus status) {
List<Tournament> tournaments; List<Tournament> tournaments;
if (Objects.nonNull(status)) { if (Objects.nonNull(status)) {
tournaments = tournamentService.findAllTournamentsWithStatus(status); tournaments = tournamentService.findAllTournamentsWithStatus(status);
} else { } else {
tournaments = tournamentService.findAllTournaments(); tournaments = tournamentService.findAllTournaments();
}
return ResponseEntity.ok(tournaments
.stream()
.map(tournamentMapper::toDto)
.toList());
} }
@GetMapping("/tournaments/{id}") return ResponseEntity.ok(tournaments
@Transactional .stream()
public ResponseEntity<TournamentDto> getTournament(@PathVariable Long id) { .map(tournamentMapper::toDto)
var tournament = tournamentService.findTournamentById(id); .toList());
}
if (tournament == null) { @GetMapping("/tournaments/{id}")
return ResponseEntity.notFound().build(); @Transactional
} public ResponseEntity<TournamentDto> getTournament(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id);
return ResponseEntity.ok(tournamentMapper.toDto(tournament)); if (tournament == null) {
return ResponseEntity.notFound().build();
} }
@PostMapping("/tournaments") return ResponseEntity.ok(tournamentMapper.toDto(tournament));
public ResponseEntity<TournamentDto> createTournament(@RequestBody TournamentDto tournamentDto) { }
Tournament tournament;
try { @PostMapping("/tournaments")
tournament = tournamentMapper.toEntity(tournamentDto); public ResponseEntity<TournamentDto> createTournament(@RequestBody TournamentDto tournamentDto) {
} catch (NullPointerException | DateTimeParseException e) { Tournament tournament;
return ResponseEntity.badRequest().build(); try {
} tournament = tournamentMapper.toEntity(tournamentDto);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentService.saveTournament(tournament))); } catch (NullPointerException | DateTimeParseException e) {
return ResponseEntity.badRequest().build();
} }
return ResponseEntity.ok(tournamentMapper.toDto(tournamentService.saveTournament(tournament)));
}
@PutMapping("/tournaments/{id}") @PutMapping("/tournaments/{id}")
public ResponseEntity<TournamentDto> updateTournament(@PathVariable Long id, @RequestBody TournamentDto tournamentDto) { public ResponseEntity<TournamentDto> updateTournament(@PathVariable Long id, @RequestBody TournamentDto tournamentDto) {
var newTournament = tournamentMapper.toEntity(tournamentDto); var newTournament = tournamentMapper.toEntity(tournamentDto);
var tournament = tournamentService.updateTournament(id, newTournament); var tournament = tournamentService.updateTournament(id, newTournament);
return ResponseEntity.ok(tournamentMapper.toDto(tournament)); return ResponseEntity.ok(tournamentMapper.toDto(tournament));
} }
@GetMapping("/tournaments/{id}/validate") @GetMapping("/tournaments/{id}/validate")
public ResponseEntity<TournamentValidationDto> validateTournament(@PathVariable Long id) { public ResponseEntity<TournamentValidationDto> validateTournament(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id); var tournament = tournamentService.findTournamentById(id);
var tournamentValidation = tournamentValidationService.validate(tournament); var tournamentValidation = tournamentValidationService.validate(tournament);
return ResponseEntity.ok(tournamentValidationMapper.toDto(tournamentValidation)); return ResponseEntity.ok(tournamentValidationMapper.toDto(tournamentValidation));
} }
@PostMapping("/tournaments/{id}/divide") @PostMapping("/tournaments/{id}/divide")
public ResponseEntity<TournamentDto> divideTournamentNew(@PathVariable Long id) { public ResponseEntity<TournamentDto> divideTournamentNew(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id); var tournament = tournamentService.findTournamentById(id);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentDivideService.divide(tournament))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentDivideService.divide(tournament)));
} }
@PostMapping("/tournaments/{id}/divide/clear") @PostMapping("/tournaments/{id}/divide/clear")
public ResponseEntity<TournamentDto> clearTournamentDivision(@PathVariable Long id) { public ResponseEntity<TournamentDto> clearTournamentDivision(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id); var tournament = tournamentService.findTournamentById(id);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentDivideService.clear(tournament))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentDivideService.clear(tournament)));
} }
@PostMapping("/tournaments/{id}/draw") @PostMapping("/tournaments/{id}/draw")
public ResponseEntity<TournamentDto> drawTournament(@PathVariable Long id) { public ResponseEntity<TournamentDto> drawTournament(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id); var tournament = tournamentService.findTournamentById(id);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentDrawService.draw(tournament))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentDrawService.draw(tournament)));
} }
@PostMapping("/tournaments/{id}/draw/clear") @PostMapping("/tournaments/{id}/draw/clear")
public ResponseEntity<TournamentDto> clearTournamentDraw(@PathVariable Long id) { public ResponseEntity<TournamentDto> clearTournamentDraw(@PathVariable Long id) {
var tournament = tournamentService.findTournamentById(id); var tournament = tournamentService.findTournamentById(id);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentDrawService.clear(tournament))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentDrawService.clear(tournament)));
} }
@PostMapping("/tournaments/{tournamentId}/rounds/{roundId}/start") @PostMapping("/tournaments/{tournamentId}/rounds/{roundId}/start")
public ResponseEntity<TournamentDto> startRound(@PathVariable Long tournamentId, @PathVariable Long roundId) { public ResponseEntity<TournamentDto> startRound(@PathVariable Long tournamentId, @PathVariable Long roundId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startRound(tournament, roundId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startRound(tournament, roundId)));
} }
@PostMapping("/tournaments/{tournamentId}/rounds/{roundId}/finish") @PostMapping("/tournaments/{tournamentId}/rounds/{roundId}/finish")
public ResponseEntity<TournamentDto> finishRound(@PathVariable Long tournamentId, @PathVariable Long roundId) { public ResponseEntity<TournamentDto> finishRound(@PathVariable Long tournamentId, @PathVariable Long roundId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.finishRound(tournament, roundId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.finishRound(tournament, roundId)));
} }
@PostMapping("/tournaments/{tournamentId}/groups/{groupId}/finish") @PostMapping("/tournaments/{tournamentId}/groups/{groupId}/finish")
public ResponseEntity<TournamentDto> finishGroup(@PathVariable Long tournamentId, @PathVariable Long groupId) { public ResponseEntity<TournamentDto> finishGroup(@PathVariable Long tournamentId, @PathVariable Long groupId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.finishGroup(tournament, groupId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.finishGroup(tournament, groupId)));
} }
@PostMapping("/tournaments/{tournamentId}/groups/{groupId}/reopen") @PostMapping("/tournaments/{tournamentId}/groups/{groupId}/reopen")
public ResponseEntity<TournamentDto> reopenGroup(@PathVariable Long tournamentId, @PathVariable Long groupId) { public ResponseEntity<TournamentDto> reopenGroup(@PathVariable Long tournamentId, @PathVariable Long groupId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.reopenGroup(tournament, groupId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.reopenGroup(tournament, groupId)));
} }
@PostMapping("/tournaments/{tournamentId}/groups/{groupId}/new") @PostMapping("/tournaments/{tournamentId}/groups/{groupId}/new")
public ResponseEntity<TournamentDto> newRound(@PathVariable Long tournamentId, @PathVariable Long groupId) { public ResponseEntity<TournamentDto> newRound(@PathVariable Long tournamentId, @PathVariable Long groupId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId)));
} }
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start") @PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId, public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId,
@RequestParam("court") Long court, @RequestParam("counter") Long counter) { @PathVariable Long matchId,
var tournament = tournamentService.findTournamentById(tournamentId); @RequestParam("court") Long court,
@RequestParam("counter") Long counter) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
} }
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/stop") @PostMapping("/tournaments/{tournamentId}/matches/{matchId}/stop")
public ResponseEntity<TournamentDto> stopMatch(@PathVariable Long tournamentId, @PathVariable Long matchId) { public ResponseEntity<TournamentDto> stopMatch(@PathVariable Long tournamentId, @PathVariable Long matchId) {
var tournament = tournamentService.findTournamentById(tournamentId); var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.stopMatch(tournament, matchId))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.stopMatch(tournament, matchId)));
} }
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}") @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,
var tournament = tournamentService.findTournamentById(tournamentId); @PathVariable Long matchId,
@RequestBody ResultDto resultDto) {
var tournament = tournamentService.findTournamentById(tournamentId);
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto))); return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.saveResult(tournament, matchId, resultDto)));
} }
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/paid/{paid}") @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,
var tournament = tournamentService.findTournamentById(tournamentId); @PathVariable Long playerId,
@PathVariable Boolean paid) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePaid(tournament, playerId, paid); tournamentPlayService.updatePaid(tournament, playerId, paid);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }
@PatchMapping("/tournaments/{tournamentId}/players/{playerId}/present/{present}") @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,
var tournament = tournamentService.findTournamentById(tournamentId); @PathVariable Long playerId,
@PathVariable Boolean present) {
var tournament = tournamentService.findTournamentById(tournamentId);
tournamentPlayService.updatePresent(tournament, playerId, present); tournamentPlayService.updatePresent(tournament, playerId, present);
return ResponseEntity.noContent().build(); return ResponseEntity.noContent().build();
} }
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/substitutions") @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,
var tournament = tournamentService.findTournamentById(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)));
}
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.playerSubstitutions(tournament, playerId, substitutions)));
}
} }

View File

@@ -26,7 +26,7 @@ public class Event extends AbstractEntity {
@ManyToOne @ManyToOne
private Tournament tournament; private Tournament tournament;
@OneToMany(mappedBy = "event", cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Registration> registrations; private List<Registration> registrations;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)

View File

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

View File

@@ -30,11 +30,9 @@ public class Match extends AbstractEntity {
private Round round; private Round round;
@ManyToOne @ManyToOne
@JoinColumn(name = "team1_id")
private Team team1; private Team team1;
@ManyToOne @ManyToOne
@JoinColumn(name = "team2_id")
private Team team2; private Team team2;
private Boolean played; private Boolean played;

View File

@@ -58,11 +58,11 @@ public class Player extends AbstractEntity {
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private PlayerStrength strength; private PlayerStrength strength;
@OneToMany(mappedBy = "player", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Registration> registrations; private List<Registration> registrations;// = new ArrayList<>();
@OneToMany(mappedBy = "partner", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Registration> partnerRegistrations; private List<Registration> partnerRegistrations;// = new ArrayList<>();
public String getFullName() { public String getFullName() {
return hasLength(middleName) ? return hasLength(middleName) ?

View File

@@ -20,8 +20,8 @@ public class Registration extends AbstractEntity {
@ManyToOne @ManyToOne
private Event event; private Event event;
// @ManyToOne @ManyToOne
// private Tournament tournament; private Tournament tournament;
@ManyToOne @ManyToOne
@JoinColumn(name = "player_id") @JoinColumn(name = "player_id")

View File

@@ -27,7 +27,7 @@ public class Round extends AbstractEntity {
private Status status; private Status status;
@OneToMany(mappedBy = "round", cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@OrderBy("id") @OrderBy("id")
private List<Match> matches; private List<Match> matches;

View File

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

View File

@@ -35,7 +35,7 @@ public class Tournament extends AbstractEntity {
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private TournamentStatus status; private TournamentStatus status;
@OneToMany(mappedBy = "tournament", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Event> events; private List<Event> events;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)

View File

@@ -96,12 +96,14 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
for (var event : tournament.getEvents()) { for (var event : tournament.getEvents()) {
if (event.getGroups() != null) { if (event.getGroups() != null) {
for (var group : event.getGroups()) { for (var group : event.getGroups()) {
for (var round : group.getRounds()) { if (group.getRounds() != null) {
for (var match : round.getMatches()) { for (var round : group.getRounds()) {
if (match.getStatus() == Status.IN_PROGRESS && match.getCounter() != null) { for (var match : round.getMatches()) {
var counter = getTournamentPlayerFromPlayerId(tournament, match.getCounter().getId()); if (match.getStatus() == Status.IN_PROGRESS && match.getCounter() != null) {
if (counter != null) { var counter = getTournamentPlayerFromPlayerId(tournament, match.getCounter().getId());
playersCounting.add(counter.getId()); if (counter != null) {
playersCounting.add(counter.getId());
}
} }
} }
} }
@@ -118,10 +120,12 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
for (var event : tournament.getEvents()) { for (var event : tournament.getEvents()) {
if (event.getGroups() != null) { if (event.getGroups() != null) {
for (var group : event.getGroups()) { for (var group : event.getGroups()) {
for (var round : group.getRounds()) { if (group.getRounds() != null) {
for (var match : round.getMatches()) { for (var round : group.getRounds()) {
if (match.getStatus() == Status.IN_PROGRESS) { for (var match : round.getMatches()) {
playersPlaying.addAll(getPlayersInMatch(tournament, match)); if (match.getStatus() == Status.IN_PROGRESS) {
playersPlaying.addAll(getPlayersInMatch(tournament, match));
}
} }
} }
} }

View File

@@ -27,7 +27,7 @@ public class RegistrationService {
.findAny(); .findAny();
if (optionalExistingPlayerRegistration.isEmpty()) { // no previous registration for this event if (optionalExistingPlayerRegistration.isEmpty()) { // no previous registration for this event
var newRegistration = new Registration(); var newRegistration = new Registration();
// newRegistration.setTournament(tournament); newRegistration.setTournament(tournament);
newRegistration.setEvent(event); newRegistration.setEvent(event);
newRegistration.setPlayer(player); newRegistration.setPlayer(player);
if (eventRegistration.getPartner() != null) { if (eventRegistration.getPartner() != null) {
@@ -53,7 +53,9 @@ public class RegistrationService {
private void removeEventFromTournamentPlayer(Tournament tournament, Player player, Event event) { private void removeEventFromTournamentPlayer(Tournament tournament, Player player, Event event) {
var tournamentPlayer = findOrAddTournamentPlayer(tournament, player); var tournamentPlayer = findOrAddTournamentPlayer(tournament, player);
tournamentPlayer.getEvents().removeIf(eventType -> eventType.equals(event.getType().name())); tournamentPlayer.getEvents().removeIf(eventType -> eventType.equals(event.getType().name()));
tournamentPlayer.getSubstitutions().removeIf(substitution -> substitution.getEvent().equals(event)); if (tournamentPlayer.getSubstitutions() != null) {
tournamentPlayer.getSubstitutions().removeIf(substitution -> substitution.getEvent().equals(event));
}
} }
private void addEventToTournamentPlayer(Tournament tournament, Player player, Event event) { private void addEventToTournamentPlayer(Tournament tournament, Player player, Event event) {

View File

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

View File

@@ -168,22 +168,12 @@ public class TournamentPlayService {
round.setMatches(matches); round.setMatches(matches);
printRound(round, standings);
group.getRounds().add(round); group.getRounds().add(round);
tournamentRepository.save(tournament); tournamentRepository.save(tournament);
return 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) { public Tournament playerSubstitutions(Tournament tournament, Long playerId, TournamentPlayerSubstitutionDto[] substitutions) {
var tournamentPlayer = getTournamentPlayer(tournament, playerId); var tournamentPlayer = getTournamentPlayer(tournament, playerId);
@@ -230,6 +220,21 @@ public class TournamentPlayService {
return null; 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 {} private static class ConflictInDrawException extends RuntimeException {}
@@ -244,7 +249,6 @@ public class TournamentPlayService {
if (!findPreviousMatchOccurence(newMatch.getTeam1(), remainingTeams.get(opponentIndex), group)) { if (!findPreviousMatchOccurence(newMatch.getTeam1(), remainingTeams.get(opponentIndex), group)) {
newMatch.setTeam2(remainingTeams.get(opponentIndex)); newMatch.setTeam2(remainingTeams.get(opponentIndex));
} else { } else {
log.info("Wedstrijd %s - %s kwam al eerder voor.".formatted(newMatch.getTeam1().toString(), remainingTeams.get(opponentIndex).toString()));
continue; continue;
} }
var newRemainingTeams = getRemainingTeams(remainingTeams, opponentIndex); var newRemainingTeams = getRemainingTeams(remainingTeams, opponentIndex);