1 | package org.hplr.tournament.core.usecases.service; | |
2 | ||
3 | import lombok.RequiredArgsConstructor; | |
4 | import org.hplr.game.core.model.vo.GameArmy; | |
5 | import org.hplr.game.core.model.vo.GameSidePlayerData; | |
6 | import org.hplr.library.exception.HPLRIllegalArgumentException; | |
7 | import org.hplr.library.exception.HPLRIllegalStateException; | |
8 | import org.hplr.library.exception.HPLRValidationException; | |
9 | import org.hplr.tournament.core.model.Tournament; | |
10 | import org.hplr.tournament.core.model.TournamentSnapshot; | |
11 | import org.hplr.tournament.core.model.TournamentValidator; | |
12 | import org.hplr.tournament.core.model.vo.TournamentPlayer; | |
13 | import org.hplr.tournament.core.usecases.port.in.AddPlayerToTournamentUseCaseInterface; | |
14 | import org.hplr.tournament.core.usecases.port.out.command.UpdateTournamentQueryInterface; | |
15 | import org.hplr.tournament.core.usecases.port.out.query.SelectTournamentByTournamentIdQueryInterface; | |
16 | import org.hplr.tournament.core.usecases.service.dto.AddPlayerToTournamentDto; | |
17 | import org.hplr.user.core.model.Player; | |
18 | import org.hplr.user.core.usecases.port.out.query.SelectPlayerByUserIdQueryInterface; | |
19 | import org.springframework.stereotype.Service; | |
20 | ||
21 | import java.util.NoSuchElementException; | |
22 | import java.util.UUID; | |
23 | ||
24 | @Service | |
25 | @RequiredArgsConstructor | |
26 | public class AddPlayerToTournamentUseCaseService implements AddPlayerToTournamentUseCaseInterface { | |
27 | private final SelectPlayerByUserIdQueryInterface selectPlayerByUserId; | |
28 | private final SelectTournamentByTournamentIdQueryInterface selectTournamentByTournamentId; | |
29 | private final UpdateTournamentQueryInterface updateTournamentQueryInterface; | |
30 | ||
31 | @Override | |
32 | public UUID addPlayerToTournament(AddPlayerToTournamentDto addPlayerToTournamentDto) { | |
33 | ||
34 | Player player = Player.fromDto(selectPlayerByUserId | |
35 | .selectPlayerByUserId( | |
36 | addPlayerToTournamentDto.playerId()).orElseThrow(NoSuchElementException::new) | |
37 | ); | |
38 | Tournament tournament = Tournament.fromSelectDto(selectTournamentByTournamentId | |
39 | .selectTournamentByTournamentId(addPlayerToTournamentDto.tournamentId()) | |
40 | .orElseThrow(NoSuchElementException::new) | |
41 | ); | |
42 | try { | |
43 |
1
1. addPlayerToTournament : removed call to org/hplr/tournament/core/model/TournamentValidator::validateIfPlayerIsNotInTheTournament → KILLED |
TournamentValidator.validateIfPlayerIsNotInTheTournament(tournament, player); |
44 |
1
1. addPlayerToTournament : removed call to org/hplr/tournament/core/model/TournamentValidator::validateIfTournamentSizeIsNotReached → SURVIVED |
TournamentValidator.validateIfTournamentSizeIsNotReached(tournament); |
45 | } catch (HPLRIllegalArgumentException ex) { | |
46 | throw new HPLRValidationException(ex.getMessage()); | |
47 | } | |
48 | TournamentPlayer tournamentPlayer = new TournamentPlayer( | |
49 | addPlayerToTournamentDto.allegiance(), | |
50 | new GameSidePlayerData( | |
51 | player, | |
52 | GameArmy.fromDto(addPlayerToTournamentDto.primaryArmy()), | |
53 | addPlayerToTournamentDto.allyArmyList().stream().map(GameArmy::fromDto).toList() | |
54 | ) | |
55 | ); | |
56 | try { | |
57 |
1
1. addPlayerToTournament : removed call to org/hplr/tournament/core/model/TournamentValidator::validateIfPointSizeIsLegal → KILLED |
TournamentValidator.validateIfPointSizeIsLegal(tournament, tournamentPlayer); |
58 | } catch (HPLRIllegalStateException ex) { | |
59 | throw new HPLRValidationException(ex.getMessage()); | |
60 | } tournament.getPlayerList().add(tournamentPlayer); | |
61 | TournamentSnapshot tournamentSnapshot = tournament.toSnapshot(); | |
62 |
1
1. addPlayerToTournament : removed call to org/hplr/tournament/core/usecases/port/out/command/UpdateTournamentQueryInterface::updateTournament → KILLED |
updateTournamentQueryInterface.updateTournament(tournamentSnapshot); |
63 |
1
1. addPlayerToTournament : replaced return value with null for org/hplr/tournament/core/usecases/service/AddPlayerToTournamentUseCaseService::addPlayerToTournament → KILLED |
return tournamentSnapshot.tournamentId().tournamentId(); |
64 | } | |
65 | } | |
Mutations | ||
43 |
1.1 |
|
44 |
1.1 |
|
57 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |