mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2025-12-22 22:41:59 +00:00
add TeamExists throw when team already in DB
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package de.pnreichmuth.timekeep_backend.services;
|
package de.pnreichmuth.timekeep_backend.services;
|
||||||
|
|
||||||
|
import de.pnreichmuth.timekeep_backend.entities.Racer;
|
||||||
import de.pnreichmuth.timekeep_backend.entities.Team;
|
import de.pnreichmuth.timekeep_backend.entities.Team;
|
||||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamExistsException;
|
import de.pnreichmuth.timekeep_backend.exceptions.TeamExistsException;
|
||||||
import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
|
import de.pnreichmuth.timekeep_backend.exceptions.TeamNotFoundException;
|
||||||
|
import de.pnreichmuth.timekeep_backend.repositories.RacerRepository;
|
||||||
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
import de.pnreichmuth.timekeep_backend.repositories.TeamRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -17,6 +19,7 @@ import java.util.UUID;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TeamService {
|
public class TeamService {
|
||||||
private final TeamRepository teamRepository;
|
private final TeamRepository teamRepository;
|
||||||
|
private final RacerRepository racerRepository;
|
||||||
|
|
||||||
public Team getTeam(UUID id){
|
public Team getTeam(UUID id){
|
||||||
return teamRepository.findById(id).orElse(null);
|
return teamRepository.findById(id).orElse(null);
|
||||||
@@ -32,13 +35,17 @@ public class TeamService {
|
|||||||
return teamRepository.findAll();
|
return teamRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTeam(){
|
public Team createTeam(){
|
||||||
Team team = new Team();
|
Team team = new Team();
|
||||||
|
Racer racer = new Racer(null,"Paul", "Reichmuth",false,"0");
|
||||||
|
team.addMember(racer);
|
||||||
|
racerRepository.save(racer);
|
||||||
teamRepository.save(team);
|
teamRepository.save(team);
|
||||||
log.info("Team created: {}", team);
|
log.info("Team created: {}", team);
|
||||||
|
return team;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTeam(Team team){
|
public void createTeam(Team team) throws TeamExistsException{
|
||||||
if(teamRepository.existsByTeamName(team.getTeamName())){
|
if(teamRepository.existsByTeamName(team.getTeamName())){
|
||||||
throw new TeamExistsException("A team by this name already exists.", team);
|
throw new TeamExistsException("A team by this name already exists.", team);
|
||||||
}
|
}
|
||||||
@@ -46,9 +53,10 @@ public class TeamService {
|
|||||||
log.info("Team created: {}", team);
|
log.info("Team created: {}", team);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTeam(String name){
|
public void createTeam(String name) throws TeamExistsException{
|
||||||
Team tempTeam = new Team();
|
Team tempTeam = new Team();
|
||||||
tempTeam.setTeamName(name);
|
tempTeam.setTeamName(name);
|
||||||
|
if(teamRepository.existsByTeamName(tempTeam.getTeamName())) throw new TeamExistsException("A team by this name already exists.", tempTeam);
|
||||||
teamRepository.save(tempTeam);
|
teamRepository.save(tempTeam);
|
||||||
log.info("Team created: {}", tempTeam);
|
log.info("Team created: {}", tempTeam);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user