Various improvements
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -168,6 +168,7 @@ public class TestController {
|
||||
tournamentDto.setMaxEvents(2L);
|
||||
tournamentDto.setCourts(9L);
|
||||
tournamentDto.setCostsPerEvent(List.of(6f, 10f, 0f));
|
||||
tournamentDto.setActive(true);
|
||||
return tournamentDto;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package nl.connectedit.swiss.dto;
|
||||
package nl.connectedit.swiss.domain;
|
||||
|
||||
import java.util.Comparator;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -27,8 +27,7 @@ public class Event extends AbstractEntity {
|
||||
private Tournament tournament;
|
||||
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
// @Builder.Default
|
||||
private List<Registration> registrations;// = new ArrayList<>();
|
||||
private List<Registration> registrations;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status;
|
||||
@@ -37,7 +36,7 @@ public class Event extends AbstractEntity {
|
||||
private EventType type;
|
||||
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private List<Group> groups;// = new ArrayList<>();
|
||||
private List<Group> groups;
|
||||
|
||||
public static List<Event> getBlankEventSet(Tournament tournament) {
|
||||
return Arrays.stream(EventType.values())
|
||||
|
||||
@@ -33,7 +33,12 @@ public class Group extends AbstractEntity {
|
||||
@OrderBy("name")
|
||||
private List<Round> rounds;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "eventgroup_teams",
|
||||
joinColumns = @JoinColumn(name = "group_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "teams_id")
|
||||
)
|
||||
private List<Team> teams;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,4 +37,6 @@ public class Round extends AbstractEntity {
|
||||
@ManyToOne
|
||||
private Team drawnOut;
|
||||
|
||||
private Boolean isFinalsRound = Boolean.FALSE;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package nl.connectedit.swiss.domain.entity;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -17,8 +18,8 @@ public class Team extends AbstractEntity {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private Group group;
|
||||
@ManyToMany(mappedBy = "teams", fetch = FetchType.LAZY)
|
||||
private List<Group> groups;
|
||||
|
||||
@ManyToOne
|
||||
private Player player1;
|
||||
|
||||
@@ -32,4 +32,9 @@ public class TournamentPlayer extends AbstractEntity {
|
||||
private boolean counting;
|
||||
|
||||
private Long counts;
|
||||
|
||||
public void incrementCounts() {
|
||||
this.counts++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ public class RoundDto extends AbstractDto {
|
||||
|
||||
private StandingsDto standings;
|
||||
|
||||
private Boolean isFinalsRound;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package nl.connectedit.swiss.mapper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.domain.EventType;
|
||||
import nl.connectedit.swiss.domain.Status;
|
||||
import nl.connectedit.swiss.domain.entity.Event;
|
||||
import nl.connectedit.swiss.domain.EventType;
|
||||
import nl.connectedit.swiss.domain.entity.Group;
|
||||
import nl.connectedit.swiss.dto.EventDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class EventMapper implements DtoMapper<Event, EventDto>, EntityMapper<EventDto, Event> {
|
||||
@@ -56,6 +59,7 @@ public class EventMapper implements DtoMapper<Event, EventDto>, EntityMapper<Eve
|
||||
eventDto.setGroups(
|
||||
event.getGroups()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(Group::getName))
|
||||
.map(groupMapper::toDto)
|
||||
.toList()
|
||||
);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package nl.connectedit.swiss.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.domain.entity.Group;
|
||||
import nl.connectedit.swiss.domain.entity.Round;
|
||||
import nl.connectedit.swiss.domain.entity.Team;
|
||||
import nl.connectedit.swiss.dto.RoundDto;
|
||||
import nl.connectedit.swiss.service.StandingsService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RoundMapper {
|
||||
@@ -45,6 +45,8 @@ public class RoundMapper {
|
||||
var standings = standingsService.getStandings(roundsForStandings, teamsForStandings);
|
||||
roundDto.setStandings(standingsMapper.toDto(standings));
|
||||
|
||||
roundDto.setIsFinalsRound(round.getIsFinalsRound());
|
||||
|
||||
return roundDto;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package nl.connectedit.swiss.mapper;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.domain.StandingsEntry;
|
||||
import nl.connectedit.swiss.dto.StandingsDto;
|
||||
import nl.connectedit.swiss.dto.StandingsEntryDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.dto.StandingsDto;
|
||||
import nl.connectedit.swiss.dto.StandingsEntry;
|
||||
import nl.connectedit.swiss.dto.StandingsEntryDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package nl.connectedit.swiss.mapper;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.domain.TournamentStatus;
|
||||
import nl.connectedit.swiss.domain.entity.Event;
|
||||
import nl.connectedit.swiss.domain.entity.Tournament;
|
||||
import nl.connectedit.swiss.domain.entity.TournamentPlayer;
|
||||
import nl.connectedit.swiss.dto.TournamentDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import nl.connectedit.swiss.domain.entity.Tournament;
|
||||
import nl.connectedit.swiss.domain.TournamentStatus;
|
||||
import nl.connectedit.swiss.domain.entity.TournamentPlayer;
|
||||
import nl.connectedit.swiss.dto.TournamentDto;
|
||||
import nl.connectedit.swiss.dto.TournamentPlayerDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@@ -51,6 +53,7 @@ public class TournamentMapper implements DtoMapper<Tournament, TournamentDto>, E
|
||||
tournamentDto.setEvents(
|
||||
tournament.getEvents()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(Event::getType))
|
||||
.map(eventMapper::toDto)
|
||||
.toList()
|
||||
);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package nl.connectedit.swiss.service;
|
||||
|
||||
import nl.connectedit.swiss.domain.entity.Group;
|
||||
import nl.connectedit.swiss.domain.StandingsEntry;
|
||||
import nl.connectedit.swiss.domain.entity.Match;
|
||||
import nl.connectedit.swiss.domain.entity.Round;
|
||||
import nl.connectedit.swiss.domain.entity.Team;
|
||||
import nl.connectedit.swiss.dto.StandingsEntry;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -64,6 +64,7 @@ public class TournamentDivideService {
|
||||
event.getGroups().add(group);
|
||||
} else {
|
||||
var groups = getGroups(registrations, event.getType());
|
||||
groups.forEach(group -> group.setEvent(event));
|
||||
event.getGroups().addAll(groups);
|
||||
}
|
||||
}
|
||||
@@ -146,7 +147,7 @@ nextRegistration:
|
||||
var team = new Team();
|
||||
team.setPlayer1(registration.getPlayer());
|
||||
team.setPlayer2(registration.getPartner());
|
||||
team.setGroup(group);
|
||||
team.setGroups(List.of(group));
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@ package nl.connectedit.swiss.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.java.Log;
|
||||
import nl.connectedit.swiss.domain.EventType;
|
||||
import nl.connectedit.swiss.domain.StandingsEntry;
|
||||
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.StandingsEntry;
|
||||
import nl.connectedit.swiss.repository.TournamentRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -14,7 +15,6 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static nl.connectedit.swiss.service.ServiceUtil.*;
|
||||
@@ -42,11 +42,86 @@ public class TournamentPlayService {
|
||||
}
|
||||
|
||||
public Tournament finishGroup(Tournament tournament, Long groupId) {
|
||||
getGroup(tournament, groupId).setStatus(Status.FINISHED);
|
||||
var group = getGroup(tournament, groupId);
|
||||
group.setStatus(Status.FINISHED);
|
||||
|
||||
checkForEventCompletion(tournament, group.getType());
|
||||
|
||||
tournamentRepository.save(tournament);
|
||||
return tournament;
|
||||
}
|
||||
|
||||
private void checkForEventCompletion(Tournament tournament, EventType type) {
|
||||
Group group1 = null;
|
||||
Group group2 = null;
|
||||
Event event = null;
|
||||
|
||||
for (var e : tournament.getEvents()) {
|
||||
if (e.getType() == type) {
|
||||
if (e.getGroups().size() != 2) {
|
||||
return;
|
||||
}
|
||||
group1 = e.getGroups().getFirst();
|
||||
if (group1.getStatus() != Status.FINISHED) {
|
||||
return;
|
||||
}
|
||||
|
||||
group2 = e.getGroups().getLast();
|
||||
if (group2.getStatus() != Status.FINISHED) {
|
||||
return;
|
||||
}
|
||||
event = e;
|
||||
}
|
||||
}
|
||||
|
||||
var finalsGroup = new Group();
|
||||
finalsGroup.setName(type.getText());
|
||||
finalsGroup.setType(type);
|
||||
finalsGroup.setStatus(Status.IN_PROGRESS);
|
||||
finalsGroup.setEvent(group1.getEvent());
|
||||
|
||||
var standings1 = standingsService.getStandings(group1.getRounds(), group1.getTeams());
|
||||
var standings2 = standingsService.getStandings(group2.getRounds(), group2.getTeams());
|
||||
|
||||
var team1_1 = standings1.get(0).getTeam();
|
||||
var team1_2 = standings1.get(1).getTeam();
|
||||
var team2_1 = standings2.get(0).getTeam();
|
||||
var team2_2 = standings2.get(1).getTeam();
|
||||
|
||||
team1_1.getGroups().add(finalsGroup);
|
||||
team1_2.getGroups().add(finalsGroup);
|
||||
team2_1.getGroups().add(finalsGroup);
|
||||
team2_2.getGroups().add(finalsGroup);
|
||||
|
||||
finalsGroup.setTeams(List.of(team1_1, team1_2, team2_1, team2_2));
|
||||
|
||||
var finalsRound = new Round();
|
||||
finalsRound.setGroup(finalsGroup);
|
||||
finalsRound.setStatus(Status.NOT_STARTED);
|
||||
finalsRound.setName("Finales");
|
||||
finalsRound.setIsFinalsRound(Boolean.TRUE);
|
||||
|
||||
var match1 = new Match();
|
||||
match1.setRound(finalsRound);
|
||||
match1.setType(type);
|
||||
match1.setStatus(Status.NOT_STARTED);
|
||||
match1.setPlayed(false);
|
||||
match1.setTeam1(standings1.get(0).getTeam());
|
||||
match1.setTeam2(standings2.get(0).getTeam());
|
||||
|
||||
var match2 = new Match();
|
||||
match2.setRound(finalsRound);
|
||||
match2.setType(type);
|
||||
match2.setStatus(Status.NOT_STARTED);
|
||||
match2.setPlayed(false);
|
||||
match2.setTeam1(standings1.get(1).getTeam());
|
||||
match2.setTeam2(standings2.get(1).getTeam());
|
||||
|
||||
finalsRound.setMatches(List.of(match1, match2));
|
||||
finalsGroup.setRounds(List.of(finalsRound));
|
||||
event.getGroups().add(finalsGroup);
|
||||
}
|
||||
|
||||
public Tournament reopenGroup(Tournament tournament, Long groupId) {
|
||||
getGroup(tournament, groupId).setStatus(Status.IN_PROGRESS);
|
||||
tournamentRepository.save(tournament);
|
||||
@@ -215,6 +290,7 @@ public class TournamentPlayService {
|
||||
|
||||
var countingPlayer = getPlayer(tournament, match.getCounter().getId());
|
||||
countingPlayer.setCounting(false);
|
||||
countingPlayer.incrementCounts();
|
||||
match.setCounter(null);
|
||||
|
||||
tournamentRepository.save(tournament);
|
||||
|
||||
Reference in New Issue
Block a user