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.domain.entity.Tournament;
|
||||||
import nl.connectedit.swiss.dto.ResultDto;
|
import nl.connectedit.swiss.dto.ResultDto;
|
||||||
import nl.connectedit.swiss.dto.TournamentDto;
|
import nl.connectedit.swiss.dto.TournamentDto;
|
||||||
|
import nl.connectedit.swiss.dto.TournamentPlayerSubstitutionDto;
|
||||||
import nl.connectedit.swiss.dto.TournamentValidationDto;
|
import nl.connectedit.swiss.dto.TournamentValidationDto;
|
||||||
import nl.connectedit.swiss.mapper.TournamentMapper;
|
import nl.connectedit.swiss.mapper.TournamentMapper;
|
||||||
import nl.connectedit.swiss.mapper.TournamentValidationMapper;
|
import nl.connectedit.swiss.mapper.TournamentValidationMapper;
|
||||||
@@ -196,10 +197,10 @@ public class TournamentController {
|
|||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/event/{eventId}/substitute/{substituteId}")
|
@PostMapping("/tournaments/{tournamentId}/players/{playerId}/substitutions")
|
||||||
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId, @PathVariable Long playerId, @PathVariable Long eventId, @PathVariable Long substituteId) {
|
public ResponseEntity<TournamentDto> substitutePlayer(@PathVariable Long tournamentId, @PathVariable Long playerId, @RequestBody TournamentPlayerSubstitutionDto[] substitutions) {
|
||||||
var tournament = tournamentService.findTournamentById(tournamentId);
|
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)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ManyToOne
|
// @ManyToMany(mappedBy = "substitutions", fetch = FetchType.LAZY)
|
||||||
private TournamentPlayer tournamentPlayer;
|
// private List<TournamentPlayer> tournamentPlayer;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private Event event;
|
private Event event;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, Tourn
|
|||||||
|
|
||||||
private TournamentPlayerSubstitutionDto mapSubstitution(TournamentPlayerSubstitution tournamentPlayerSubstitution) {
|
private TournamentPlayerSubstitutionDto mapSubstitution(TournamentPlayerSubstitution tournamentPlayerSubstitution) {
|
||||||
var tournamentPlayerSubstitutionDto = new TournamentPlayerSubstitutionDto();
|
var tournamentPlayerSubstitutionDto = new TournamentPlayerSubstitutionDto();
|
||||||
|
tournamentPlayerSubstitutionDto.setSubstitutionId(tournamentPlayerSubstitution.getId());
|
||||||
tournamentPlayerSubstitutionDto.setEvent(tournamentPlayerSubstitution.getEvent().getType().name());
|
tournamentPlayerSubstitutionDto.setEvent(tournamentPlayerSubstitution.getEvent().getType().name());
|
||||||
if (tournamentPlayerSubstitution.getSubstitute() != null) {
|
if (tournamentPlayerSubstitution.getSubstitute() != null) {
|
||||||
tournamentPlayerSubstitutionDto.setSubstitute(toDto(tournamentPlayerSubstitution.getSubstitute()));
|
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.TournamentStatus;
|
||||||
import nl.connectedit.swiss.domain.entity.*;
|
import nl.connectedit.swiss.domain.entity.*;
|
||||||
import nl.connectedit.swiss.dto.ResultDto;
|
import nl.connectedit.swiss.dto.ResultDto;
|
||||||
|
import nl.connectedit.swiss.dto.TournamentPlayerSubstitutionDto;
|
||||||
import nl.connectedit.swiss.repository.TournamentRepository;
|
import nl.connectedit.swiss.repository.TournamentRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -183,17 +184,24 @@ public class TournamentPlayService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tournament substitutePlayer(Tournament tournament, Long eventId, Long playerId, Long substituteId) {
|
public Tournament playerSubstitutions(Tournament tournament, Long playerId, TournamentPlayerSubstitutionDto[] substitutions) {
|
||||||
var event = getEvent(tournament, eventId);
|
|
||||||
var tournamentPlayer = getTournamentPlayer(tournament, playerId);
|
var tournamentPlayer = getTournamentPlayer(tournament, playerId);
|
||||||
var substitute = getTournamentPlayer(tournament, substituteId);
|
|
||||||
|
|
||||||
var substitution = new TournamentPlayerSubstitution();
|
var playerSubstitutions = new ArrayList<TournamentPlayerSubstitution>();
|
||||||
substitution.setEvent(event);
|
|
||||||
substitution.setTournamentPlayer(tournamentPlayer);
|
|
||||||
substitution.setSubstitute(substitute);
|
|
||||||
|
|
||||||
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);
|
tournamentRepository.save(tournament);
|
||||||
return tournament;
|
return tournament;
|
||||||
@@ -208,6 +216,15 @@ public class TournamentPlayService {
|
|||||||
return null;
|
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 {}
|
private static class ConflictInDrawException extends RuntimeException {}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ spring:
|
|||||||
# - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
# - org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
||||||
# - org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
|
# - org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=swiss
|
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=swiss2
|
||||||
username: ${DB_USERNAME:postgres}
|
username: ${DB_USERNAME:postgres}
|
||||||
password: ${DB_PASSWORD:postgres}
|
password: ${DB_PASSWORD:postgres}
|
||||||
flyway:
|
flyway:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ spring:
|
|||||||
password: ${DB_PASSWORD:postgres}
|
password: ${DB_PASSWORD:postgres}
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
ddl-auto: none
|
ddl-auto: update
|
||||||
flyway:
|
flyway:
|
||||||
url: jdbc:postgresql://${DB_URL:localhost:5432}/${DB_NAME}?currentSchema=swiss
|
url: jdbc:postgresql://${DB_URL:localhost:5432}/${DB_NAME}?currentSchema=swiss
|
||||||
user: ${DB_USERNAME:postgres}
|
user: ${DB_USERNAME:postgres}
|
||||||
|
|||||||
Reference in New Issue
Block a user