Compare commits

..

2 Commits

Author SHA1 Message Date
83c9b53330 Cleanup
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
2025-08-18 23:27:31 +02:00
36c8f3b22f Add match counter 2025-08-18 23:27:14 +02:00
10 changed files with 54 additions and 17 deletions

View File

@@ -156,11 +156,12 @@ public class TournamentController {
return ResponseEntity.ok(tournamentMapper.toDto(tournamentPlayService.newRound(tournament, groupId)));
}
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start/{court}")
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId, @PathVariable Long court) {
@PostMapping("/tournaments/{tournamentId}/matches/{matchId}/start")
public ResponseEntity<TournamentDto> startMatch(@PathVariable Long tournamentId, @PathVariable Long matchId,
@RequestParam("court") Long court, @RequestParam("counter") Long counter) {
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")

View File

@@ -31,9 +31,9 @@ public class Group extends AbstractEntity {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OrderBy("name")
private List<Round> rounds;// = new ArrayList<>();
private List<Round> rounds;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Team> teams;// = new ArrayList<>();
private List<Team> teams;
}

View File

@@ -39,8 +39,11 @@ public class Match extends AbstractEntity {
private Long court;
@ManyToOne
private Player counter;
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Game> games;// = new ArrayList<>();
private List<Game> games;
private LocalDateTime startTime;

View File

@@ -28,10 +28,11 @@ public class Round extends AbstractEntity {
private Status status;
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Match> matches;// = new ArrayList<>();
@OrderBy("id")
private List<Match> matches;
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
private List<Team> quit;// = new ArrayList<>();
private List<Team> quit;
@ManyToOne
private Team drawnOut;

View File

@@ -28,4 +28,8 @@ public class TournamentPlayer extends AbstractEntity {
private boolean paid;
private boolean present;
private boolean counting;
private Long counts;
}

View File

@@ -29,4 +29,6 @@ public class MatchDto extends AbstractDto {
private LocalDateTime endTime;
private Long court;
private PlayerDto counter;
}

View File

@@ -20,4 +20,8 @@ public class TournamentPlayerDto extends AbstractDto {
private Boolean present;
private Boolean counting;
private Long counts;
}

View File

@@ -13,6 +13,8 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
private final GameMapper gameMapper;
private final PlayerMapper playerMapper;
@Override
public MatchDto toDto(Match match) {
var matchDto = new MatchDto();
@@ -25,6 +27,9 @@ public class MatchMapper implements DtoMapper<Match, MatchDto> {
matchDto.setStartTime(match.getStartTime());
matchDto.setEndTime(match.getEndTime());
matchDto.setCourt(match.getCourt());
if (match.getCounter() != null) {
matchDto.setCounter(playerMapper.toDto(match.getCounter()));
}
if (match.getGames() != null) {
matchDto.setGames(

View File

@@ -13,8 +13,6 @@ import java.util.ArrayList;
@RequiredArgsConstructor
public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, TournamentPlayerDto> {
private final PlayerMapper playerMapper;
@Override
public TournamentPlayerDto toDto(TournamentPlayer tournamentPlayer) {
var tournamentPlayerDto = new TournamentPlayerDto();
@@ -23,6 +21,8 @@ public class TournamentPlayerMapper implements DtoMapper<TournamentPlayer, Tourn
tournamentPlayerDto.setEvents(new ArrayList<>(tournamentPlayer.getEvents()));
tournamentPlayerDto.setPaid(tournamentPlayer.isPaid());
tournamentPlayerDto.setPresent(tournamentPlayer.isPresent());
tournamentPlayerDto.setCounting(tournamentPlayer.isCounting());
tournamentPlayerDto.setCounts(tournamentPlayer.getCounts());
return tournamentPlayerDto;
}

View File

@@ -166,26 +166,39 @@ public class TournamentPlayService {
return false;
}
private boolean playerHasSkippedRoundBefore(Player player, Tournament tournament) {
var hasSkippedRound = false;
return hasSkippedRound;
}
public Tournament startMatch(Tournament tournament, Long matchId, Long court) {
public Tournament startMatch(Tournament tournament, Long matchId, Long court, Long counter) {
var match = getMatch(tournament, matchId);
match.setStatus(Status.IN_PROGRESS);
match.setStartTime(LocalDateTime.now());
match.setCourt(court);
var countingPlayer = getPlayer(tournament, counter);
countingPlayer.setCounting(true);
match.setCounter(countingPlayer.getPlayer());
tournamentRepository.save(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) {
var match = getMatch(tournament, matchId);
match.setStatus(Status.NOT_STARTED);
match.setStartTime(null);
match.setCourt(null);
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
countingPlayer.setCounting(false);
match.setCounter(null);
tournamentRepository.save(tournament);
return tournament;
}
@@ -200,6 +213,10 @@ public class TournamentPlayService {
match.getGames().clear();
match.getGames().addAll(resultToGames(result, match));
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
countingPlayer.setCounting(false);
match.setCounter(null);
tournamentRepository.save(tournament);
return tournament;
}