This commit is contained in:
@@ -6,6 +6,7 @@ import nl.connectedit.swiss.domain.TournamentStatus;
|
||||
import nl.connectedit.swiss.domain.entity.Tournament;
|
||||
import nl.connectedit.swiss.dto.ResultDto;
|
||||
import nl.connectedit.swiss.dto.TournamentDto;
|
||||
import nl.connectedit.swiss.dto.TournamentPlayerSubstitutionDto;
|
||||
import nl.connectedit.swiss.dto.TournamentValidationDto;
|
||||
import nl.connectedit.swiss.mapper.TournamentMapper;
|
||||
import nl.connectedit.swiss.mapper.TournamentValidationMapper;
|
||||
@@ -196,10 +197,10 @@ public class TournamentController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/event/{eventId}/substitute/{substituteId}")
|
||||
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Long eventId, @PathVariable Long substituteId) {
|
||||
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/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.substitutePlayer(tournament, eventId, playerId, substituteId)));
|
||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.playerSubstitutions(tournament, playerId, substitutions)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ public class TournamentPlayerSubstitution extends AbstractEntity {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private TournamentPlayer tournamentPlayer;
|
||||
// @ManyToMany(mappedBy = "substitutions", fetch = FetchType.LAZY)
|
||||
// private List<TournamentPlayer> tournamentPlayer;
|
||||
|
||||
@ManyToOne
|
||||
private Event event;
|
||||
|
||||
@@ -38,6 +38,7 @@ public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, Tourn
|
||||
|
||||
private TournamentPlayerSubstitutionDto mapSubstitution(TournamentPlayerSubstitution tournamentPlayerSubstitution) {
|
||||
var tournamentPlayerSubstitutionDto = new TournamentPlayerSubstitutionDto();
|
||||
tournamentPlayerSubstitutionDto.setSubstitutionId(tournamentPlayerSubstitution.getId());
|
||||
tournamentPlayerSubstitutionDto.setEvent(tournamentPlayerSubstitution.getEvent().getType().name());
|
||||
if (tournamentPlayerSubstitution.getSubstitute() != null) {
|
||||
tournamentPlayerSubstitutionDto.setSubstitute(toDto(tournamentPlayerSubstitution.getSubstitute()));
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user