Invallers
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good

This commit is contained in:
2025-09-17 08:58:45 +02:00
parent da7ea66d3e
commit b4bbefff46
6 changed files with 34 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import nl.connectedit.swiss.domain.Status;
import nl.connectedit.swiss.domain.TournamentStatus;
import nl.connectedit.swiss.domain.entity.*;
import nl.connectedit.swiss.dto.ResultDto;
import nl.connectedit.swiss.dto.TournamentPlayerSubstitutionDto;
import nl.connectedit.swiss.repository.TournamentRepository;
import org.springframework.stereotype.Service;
@@ -183,17 +184,24 @@ public class TournamentPlayService {
}
}
public Tournament substitutePlayer(Tournament tournament, Long eventId, Long playerId, Long substituteId) {
var event = getEvent(tournament, eventId);
public Tournament playerSubstitutions(Tournament tournament, Long playerId, TournamentPlayerSubstitutionDto[] substitutions) {
var tournamentPlayer = getTournamentPlayer(tournament, playerId);
var substitute = getTournamentPlayer(tournament, substituteId);
var substitution = new TournamentPlayerSubstitution();
substitution.setEvent(event);
substitution.setTournamentPlayer(tournamentPlayer);
substitution.setSubstitute(substitute);
var playerSubstitutions = new ArrayList<TournamentPlayerSubstitution>();
tournamentPlayer.getSubstitutions().add(substitution); //TODO
for (var substitution : substitutions) {
var playerSubstitution = new TournamentPlayerSubstitution();
var eventType = EventType.valueOf(substitution.getEvent());
var event = getEventByType(tournament, eventType);
playerSubstitution.setEvent(event);
var substitute = getTournamentPlayer(tournament, substitution.getSubstitute().getPlayerId());
playerSubstitution.setSubstitute(substitute);
playerSubstitutions.add(playerSubstitution);
}
tournamentPlayer.setSubstitutions(playerSubstitutions);
tournamentRepository.save(tournament);
return tournament;
@@ -208,6 +216,15 @@ public class TournamentPlayService {
return null;
}
private Event getEventByType(Tournament tournament, EventType eventType) {
for (var event : tournament.getEvents()) {
if (event.getType().equals(eventType)) {
return event;
}
}
return null;
}
private static class ConflictInDrawException extends RuntimeException {}