mirror of
https://codeberg.org/beerbrawl/beerbrawl.git
synced 2024-09-23 01:30:52 +02:00
feat(#32): TournamentOverviewModel, small Update OverviewService
This commit is contained in:
parent
9f1e378534
commit
15980966dd
|
@ -21,6 +21,7 @@ import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentSignupTeamRes
|
|||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentUpdateDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.mapper.QualificationTeamScoreMapper;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.mapper.TeamMapper;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.mapper.TournamentOverviewMapper;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.exception.BadTournamentSignupTokenException;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.service.TournamentKoPhaseService;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.service.TournamentQualificationService;
|
||||
|
@ -71,6 +72,7 @@ public class TournamentEndpoint {
|
|||
private final TeamMapper teamMapper;
|
||||
private final QualificationTeamScoreMapper qualificationTeamScoreMapper;
|
||||
private final MatchDomainService matchDomainService;
|
||||
private final TournamentOverviewMapper tournamentOverviewMapper;
|
||||
|
||||
@Secured("ROLE_USER")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
|
@ -100,7 +102,7 @@ public class TournamentEndpoint {
|
|||
throw new AccessDeniedException("Current user isn't organizer of the tournament.");
|
||||
}
|
||||
var tournamentOverview = tournamentService.getTournamentOverview(tournamentId);
|
||||
return ResponseEntity.ok(tournamentOverview);
|
||||
return ResponseEntity.ok(tournamentOverviewMapper.modelToDto(tournamentOverview));
|
||||
}
|
||||
|
||||
@Secured("ROLE_USER")
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package at.ac.tuwien.sepr.groupphase.backend.endpoint.mapper;
|
||||
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentOverviewDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.service.models.TournamentOverviewModel;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface TournamentOverviewMapper {
|
||||
TournamentOverviewDto modelToDto(TournamentOverviewModel model);
|
||||
}
|
|
@ -102,6 +102,11 @@ public class Tournament {
|
|||
}
|
||||
this.registrationEnd = registrationEnd;
|
||||
}
|
||||
|
||||
// requires careful validation if updated retrospectively
|
||||
public void updateMaxParticipants(Long maxParticipants) {
|
||||
this.maxParticipants = maxParticipants;
|
||||
}
|
||||
|
||||
public List<Team> getTeams() {
|
||||
return Collections.unmodifiableList(teams);
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package at.ac.tuwien.sepr.groupphase.backend.service;
|
||||
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentUpdateDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.service.models.TournamentOverviewModel;
|
||||
import jakarta.validation.ValidationException;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentOverviewDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentUpdateTeamDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.entity.Team;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.entity.Tournament;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.exception.NotFoundException;
|
||||
|
||||
|
@ -58,7 +61,7 @@ public interface TournamentService {
|
|||
* @param tournamentId to locate the target tournament
|
||||
* @return OverViewDto containing wanted information about the tournament.
|
||||
*/
|
||||
TournamentOverviewDto getTournamentOverview(long tournamentId) throws NotFoundException;
|
||||
TournamentOverviewModel getTournamentOverview(long tournamentId) throws NotFoundException;
|
||||
|
||||
/**
|
||||
* Update a tournament.
|
||||
|
|
|
@ -3,7 +3,6 @@ package at.ac.tuwien.sepr.groupphase.backend.service.impl;
|
|||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.List;
|
||||
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentOverviewDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.endpoint.dto.TournamentUpdateDto;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.entity.Team;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.repository.BeerPongTableRepository;
|
||||
|
@ -12,6 +11,7 @@ import at.ac.tuwien.sepr.groupphase.backend.repository.QualificationMatchReposit
|
|||
import at.ac.tuwien.sepr.groupphase.backend.repository.TeamRepository;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.repository.TournamentRepository;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.repository.UserRepository;
|
||||
import at.ac.tuwien.sepr.groupphase.backend.service.models.TournamentOverviewModel;
|
||||
import jakarta.validation.ValidationException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -108,7 +108,7 @@ public class TournamentServiceImpl implements TournamentService {
|
|||
if (teamRepository.findAllByTournamentId(tournamentId).size() > updates.maxParticipants()) {
|
||||
throw new ValidationException("New max participating teams is lower than already registered teams.");
|
||||
}
|
||||
tournament.setMaxParticipants(updates.maxParticipants());
|
||||
tournament.updateMaxParticipants(updates.maxParticipants());
|
||||
}
|
||||
|
||||
if (updates.registrationEnd() != null) {
|
||||
|
@ -124,23 +124,23 @@ public class TournamentServiceImpl implements TournamentService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TournamentOverviewDto getTournamentOverview(long tournamentId) throws NotFoundException {
|
||||
public TournamentOverviewModel getTournamentOverview(long tournamentId) throws NotFoundException {
|
||||
LOGGER.debug("Obtain data for tournament {} overview", tournamentId);
|
||||
|
||||
var tournament = tournamentRepository.findById(tournamentId);
|
||||
if (tournament.isEmpty()) {
|
||||
throw new NotFoundException("Tournament was not found.");
|
||||
}
|
||||
var dtoBuilder = TournamentOverviewDto.builder();
|
||||
var modelBuilder = TournamentOverviewModel.builder();
|
||||
|
||||
dtoBuilder.description(tournament.get().getDescription())
|
||||
modelBuilder.description(tournament.get().getDescription())
|
||||
.name(tournament.get().getName())
|
||||
.registrationEnd(tournament.get().getRegistrationEnd())
|
||||
.maxParticipants(tournament.get().getMaxParticipants());
|
||||
|
||||
var qualificationMatches = qualificationRepository.findAllByTournamentId(tournamentId);
|
||||
if (!qualificationMatches.isEmpty()) {
|
||||
dtoBuilder.allQualificationMatches(qualificationMatches.size())
|
||||
modelBuilder.allQualificationMatches(qualificationMatches.size())
|
||||
.playedQualificationMatches(
|
||||
Math.toIntExact(
|
||||
qualificationMatches.stream()
|
||||
|
@ -150,7 +150,7 @@ public class TournamentServiceImpl implements TournamentService {
|
|||
}
|
||||
var koMatches = koStandingsRepository.findAllByTournamentId(tournamentId);
|
||||
if (!koMatches.isEmpty()) {
|
||||
dtoBuilder.allKoMatches(koMatches.size())
|
||||
modelBuilder.allKoMatches(koMatches.size())
|
||||
.playedKoMatches(
|
||||
Math.toIntExact(
|
||||
koMatches.stream()
|
||||
|
@ -161,16 +161,16 @@ public class TournamentServiceImpl implements TournamentService {
|
|||
|
||||
var tables = beerPongTableRepository.findAllByTournamentId(tournamentId);
|
||||
if (!tables.isEmpty()) {
|
||||
dtoBuilder.tables(tables.size());
|
||||
modelBuilder.tables(tables.size());
|
||||
}
|
||||
|
||||
var teams = teamRepository.findAllByTournamentId(tournamentId);
|
||||
if (!teams.isEmpty()) {
|
||||
dtoBuilder.teams(teams.size())
|
||||
modelBuilder.teams(teams.size())
|
||||
.checkedInTeams(Math.toIntExact(teams.stream().filter(Team::getCheckedIn).count()));
|
||||
}
|
||||
|
||||
return dtoBuilder.build();
|
||||
return modelBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package at.ac.tuwien.sepr.groupphase.backend.service.models;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TournamentOverviewModel {
|
||||
private String name;
|
||||
private LocalDateTime registrationEnd;
|
||||
private Long maxParticipants;
|
||||
private String description;
|
||||
// Qualification specific
|
||||
private int allQualificationMatches;
|
||||
private int playedQualificationMatches;
|
||||
// KO specific
|
||||
private int allKoMatches;
|
||||
private int playedKoMatches;
|
||||
// Teams specific
|
||||
private int teams;
|
||||
private int checkedInTeams;
|
||||
// Tables specific
|
||||
private int tables;
|
||||
private int tablesInUse;
|
||||
}
|
Loading…
Reference in a new issue