fix duplicate teams still being allowed

This commit is contained in:
2025-10-29 20:52:47 +01:00
parent 4aa9cb5b34
commit 87f5973a36
3 changed files with 25 additions and 9 deletions

View File

@@ -37,11 +37,13 @@ public class TeamRestController {
@PostMapping("createTeamDebug")
public ResponseEntity<@NonNull TeamWSTO> createTeam(){
Team team = teamService.createTeam();
try {
Team team = teamService.createTeam();
team.setTeamName("DEBUG");
teamService.updateTeam(team);
return new ResponseEntity<>(TeamWSTO.of(team), HttpStatus.CREATED);
} catch (TeamExistsException e) {
teamService.deleteTeam(team.getId());
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.CONFLICT,"This team already exists")).build();
}
}
@@ -76,8 +78,8 @@ public class TeamRestController {
}
catch(TeamNotFoundException e){
if(id != null) return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with id "+ id +" not found")).build();
else if (name != null) return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with name "+ name +" not found")).build();
else return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Must provide either id or name.")).build();
if (name != null) return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with name "+ name +" not found")).build();
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Must provide either id or name.")).build();
}
}