Add match counter
This commit is contained in:
@@ -156,11 +156,12 @@ public class TournamentController {
|
|||||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId)));
|
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start/{court}")
|
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
|
||||||
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId, @PathVariable Long court) {
|
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId,
|
||||||
|
@RequestParam("court") Long court, @RequestParam("counter") Long counter) {
|
||||||
var tournament = tournamentService.findTournamentById(tournamentId);
|
var tournament = tournamentService.findTournamentById(tournamentId);
|
||||||
|
|
||||||
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court)));
|
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.startMatch(tournament, matchId, court, counter)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/stop")
|
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/stop")
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public class Match extends AbstractEntity {
|
|||||||
|
|
||||||
private Long court;
|
private Long court;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private Player counter;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||||
private List<Game> games;// = new ArrayList<>();
|
private List<Game> games;// = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -28,4 +28,8 @@ public class TournamentPlayer extends AbstractEntity {
|
|||||||
private boolean paid;
|
private boolean paid;
|
||||||
|
|
||||||
private boolean present;
|
private boolean present;
|
||||||
|
|
||||||
|
private boolean counting;
|
||||||
|
|
||||||
|
private Long counts;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,6 @@ public class MatchDto extends AbstractDto {
|
|||||||
private LocalDateTime endTime;
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
private Long court;
|
private Long court;
|
||||||
|
|
||||||
|
private PlayerDto counter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,8 @@ public class TournamentPlayerDto extends AbstractDto {
|
|||||||
|
|
||||||
private Boolean present;
|
private Boolean present;
|
||||||
|
|
||||||
|
private Boolean counting;
|
||||||
|
|
||||||
|
private Long counts;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
|
|||||||
|
|
||||||
private final GameMapper gameMapper;
|
private final GameMapper gameMapper;
|
||||||
|
|
||||||
|
private final PlayerMapper playerMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MatchDto toDto(Match match) {
|
public MatchDto toDto(Match match) {
|
||||||
var matchDto = new MatchDto();
|
var matchDto = new MatchDto();
|
||||||
@@ -25,6 +27,9 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
|
|||||||
matchDto.setStartTime(match.getStartTime());
|
matchDto.setStartTime(match.getStartTime());
|
||||||
matchDto.setEndTime(match.getEndTime());
|
matchDto.setEndTime(match.getEndTime());
|
||||||
matchDto.setCourt(match.getCourt());
|
matchDto.setCourt(match.getCourt());
|
||||||
|
if (match.getCounter() != null) {
|
||||||
|
matchDto.setCounter(playerMapper.toDto(match.getCounter()));
|
||||||
|
}
|
||||||
|
|
||||||
if (match.getGames() != null) {
|
if (match.getGames() != null) {
|
||||||
matchDto.setGames(
|
matchDto.setGames(
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ import java.util.ArrayList;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, TournamentPlayerDto> {
|
public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, TournamentPlayerDto> {
|
||||||
|
|
||||||
private final PlayerMapper playerMapper;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TournamentPlayerDto toDto(TournamentPlayer tournamentPlayer) {
|
public TournamentPlayerDto toDto(TournamentPlayer tournamentPlayer) {
|
||||||
var tournamentPlayerDto = new TournamentPlayerDto();
|
var tournamentPlayerDto = new TournamentPlayerDto();
|
||||||
@@ -23,6 +21,8 @@ public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, Tourn
|
|||||||
tournamentPlayerDto.setEvents(new ArrayList<>(tournamentPlayer.getEvents()));
|
tournamentPlayerDto.setEvents(new ArrayList<>(tournamentPlayer.getEvents()));
|
||||||
tournamentPlayerDto.setPaid(tournamentPlayer.isPaid());
|
tournamentPlayerDto.setPaid(tournamentPlayer.isPaid());
|
||||||
tournamentPlayerDto.setPresent(tournamentPlayer.isPresent());
|
tournamentPlayerDto.setPresent(tournamentPlayer.isPresent());
|
||||||
|
tournamentPlayerDto.setCounting(tournamentPlayer.isCounting());
|
||||||
|
tournamentPlayerDto.setCounts(tournamentPlayer.getCounts());
|
||||||
|
|
||||||
return tournamentPlayerDto;
|
return tournamentPlayerDto;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,26 +166,39 @@ public class TournamentPlayService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean playerHasSkippedRoundBefore(Player player, Tournament tournament) {
|
public Tournament startMatch(Tournament tournament, Long matchId, Long court, Long counter) {
|
||||||
var hasSkippedRound = false;
|
|
||||||
|
|
||||||
return hasSkippedRound;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tournament startMatch(Tournament tournament, Long matchId, Long court) {
|
|
||||||
var match = getMatch(tournament, matchId);
|
var match = getMatch(tournament, matchId);
|
||||||
match.setStatus(Status.IN_PROGRESS);
|
match.setStatus(Status.IN_PROGRESS);
|
||||||
match.setStartTime(LocalDateTime.now());
|
match.setStartTime(LocalDateTime.now());
|
||||||
match.setCourt(court);
|
match.setCourt(court);
|
||||||
|
|
||||||
|
var countingPlayer = getPlayer(tournament, counter);
|
||||||
|
countingPlayer.setCounting(true);
|
||||||
|
match.setCounter(countingPlayer.getPlayer());
|
||||||
|
|
||||||
tournamentRepository.save(tournament);
|
tournamentRepository.save(tournament);
|
||||||
return tournament;
|
return tournament;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TournamentPlayer getPlayer(Tournament tournament, Long playerId) {
|
||||||
|
for (var tournamentPlayer : tournament.getTournamentPlayers()) {
|
||||||
|
if (playerId.equals(tournamentPlayer.getPlayer().getId())) {
|
||||||
|
return tournamentPlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Tournament stopMatch(Tournament tournament, Long matchId) {
|
public Tournament stopMatch(Tournament tournament, Long matchId) {
|
||||||
var match = getMatch(tournament, matchId);
|
var match = getMatch(tournament, matchId);
|
||||||
match.setStatus(Status.NOT_STARTED);
|
match.setStatus(Status.NOT_STARTED);
|
||||||
match.setStartTime(null);
|
match.setStartTime(null);
|
||||||
match.setCourt(null);
|
match.setCourt(null);
|
||||||
|
|
||||||
|
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
|
||||||
|
countingPlayer.setCounting(false);
|
||||||
|
match.setCounter(null);
|
||||||
|
|
||||||
tournamentRepository.save(tournament);
|
tournamentRepository.save(tournament);
|
||||||
return tournament;
|
return tournament;
|
||||||
}
|
}
|
||||||
@@ -200,6 +213,10 @@ public class TournamentPlayService {
|
|||||||
match.getGames().clear();
|
match.getGames().clear();
|
||||||
match.getGames().addAll(resultToGames(result, match));
|
match.getGames().addAll(resultToGames(result, match));
|
||||||
|
|
||||||
|
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
|
||||||
|
countingPlayer.setCounting(false);
|
||||||
|
match.setCounter(null);
|
||||||
|
|
||||||
tournamentRepository.save(tournament);
|
tournamentRepository.save(tournament);
|
||||||
return tournament;
|
return tournament;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user