Skip to content
Snippets Groups Projects
Commit 763fee43 authored by Bauer Lucca's avatar Bauer Lucca
Browse files

Merge remote-tracking branch 'origin/dev' into dev

parents d8272a69 5dd47d38
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
......@@ -20,6 +20,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
......@@ -71,8 +72,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -261,10 +261,41 @@ public class TournamentService {
else{
throw new BracketAlreadyInitializedException(tournamentId);
}
linkMatchesInNextRound(tournamentId);
tournamentRepository.save(tournament);
return tournament;
}
public void linkMatchesInNextRound(UUID tournamentId)throws TournamentIdNotFoundException {
Tournament tournament = tournamentRepository.findById(tournamentId)
.orElseThrow(() -> new TournamentIdNotFoundException(tournamentId));
int timesUsed = 0;
Map<UUID, Match> nextRoundMatches;
for (int i = 0; i < tournament.getBracket().size() - 1; i++) {
nextRoundMatches = tournament.getBracket().get(i + 1).getMatches();
List<UUID> nextRoundMatchIds = nextRoundMatches.keySet().stream().toList();
for (Map.Entry<UUID, Match> entry : tournament.getBracket().get(i).getMatches().entrySet()) {
UUID nextMatch = nextRoundMatchIds.get(0);
entry.getValue().setNextMatchId(nextMatch);
if (timesUsed > 0) {
nextRoundMatchIds.removeFirst();
timesUsed = 0;
} else {
timesUsed += 1;
}
}
}
tournamentRepository.save(tournament);
}
public Tournament fillBracketRandom(UUID tournamentId) throws TournamentIdNotFoundException {
Tournament tournament = tournamentRepository.findById(tournamentId)
.orElseThrow(() -> new TournamentIdNotFoundException(tournamentId));
......@@ -273,7 +304,7 @@ public class TournamentService {
Random random = new Random();
for(int i = 0; i < 2; i++){
for(Match match: tournament.getBracket().get(0).getMatches().values()){
if(teams.size() > 0){
if(!teams.isEmpty()){
int teamIndex = random.nextInt(0, teams.size());
match.getTeamScores().put(teams.get(teamIndex).getTeamId(), 0);
teams.remove(teamIndex);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment