refactor getTeam() to be more universal

This commit is contained in:
2026-02-04 17:48:56 +01:00
parent 600b9f062a
commit 9bad984751
3 changed files with 19 additions and 23 deletions

View File

@@ -74,19 +74,15 @@ public class TeamRestController {
String name = reqTeam.getTeamName();
Team actualTeam;
try{
if(id != null){
actualTeam = teamService.getTeam(id); //prefer uuid over name, as it is the most reliable way to find a JPA object
}
else if (name != null){
actualTeam = teamService.getTeam(name);
}
else return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, "Must provide either id or name")).build();
actualTeam = teamService.getTeam(reqTeam);
return new ResponseEntity<>(TeamWSTO.of(actualTeam), HttpStatus.OK);
}
catch(TeamNotFoundException e){
if(id != null) return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with id "+ id +" not found")).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();
else return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND,"Team with name "+ name +" not found")).build();
}
catch (IllegalArgumentException e){
return ResponseEntity.of(ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST,e.getMessage())).build();
}
}