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

16.01.2024 - Jonas has to fix TournamentService because he is such a fleißiger Junge

parent ebce256f
No related branches found
No related tags found
1 merge request!7Dev in Main Merge
......@@ -11,10 +11,9 @@ import java.util.List;
import java.util.UUID;
@Getter
@Document("Team")
@AllArgsConstructor
public class Team {
@Id
private final UUID teamId;
@Setter
private String teamName;
......
......@@ -23,7 +23,7 @@ public class Tournament implements ITournament{
private String tournamentName;
@Setter
private List<BracketRound> bracket;
private List<Team> teams;
private Map<UUID, Team> teams;
private List<UUID> users;
......@@ -32,9 +32,7 @@ public class Tournament implements ITournament{
this.tournamentId = UUID.randomUUID();
this.tournamentName = tournamentName;
this.bracket = new ArrayList<>();
this.teams = teamNames.stream().map( Team::new ).toList();
this.teams = teamNames.stream().map( Team::new ).collect(Collectors.toMap(Team::getTeamId, team -> team ));
}
public Tournament(){};
}
package hdm.mi.sthbackend.repository;
import hdm.mi.sthbackend.model.Match;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.UUID;
public interface IMatchRepository extends MongoRepository<Match, UUID> {
}
package hdm.mi.sthbackend.repository;
import hdm.mi.sthbackend.model.Player;
import hdm.mi.sthbackend.model.Tournament;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface IPlayerRepository extends MongoRepository<Player, UUID> {
}
package hdm.mi.sthbackend.repository;
import hdm.mi.sthbackend.model.Team;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.UUID;
public interface ITeamRepository extends MongoRepository<Team, UUID> {
}
......@@ -25,17 +25,16 @@ public class TournamentService {
private final Logger log = LogManager.getLogger(TournamentService.class);
ITournamentRepository tournamentRepository;
IPlayerRepository playerRepository;
ITeamRepository teamRepository;
IMatchRepository matchRepository;
@Autowired
ModelToDTOMapper mapper;
public PlayerDTO addPlayerToTeam(UUID teamId,
String playerName) throws TeamIdNotFoundException {
Team team = teamRepository.findById(teamId)
.orElseThrow(() -> new TeamIdNotFoundException(teamId));
public PlayerDTO addPlayerToTeam(UUID tournamentId, UUID teamId,
String playerName) throws TournamentIdNotFoundException, TeamIdNotFoundException {
Tournament tournament = tournamentRepository.findById(tournamentId)
.orElseThrow(() -> new TournamentIdNotFoundException( tournamentId));
Team team = Optional.ofNullable( tournament.getTeams().get( teamId )).orElseThrow(() -> new TeamIdNotFoundException(teamId)) ;
Player newPlayer = new Player(UUID.randomUUID(), playerName);
team.getTeamMembers()
......
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