mirror of
https://github.com/PaulReichmuth/timekeep-backend.git
synced 2026-02-06 04:53:25 +00:00
refactor getTeam() to be more universal
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user