Addd user retrieval if exists on creation for Coach and Athlete
This commit is contained in:
@@ -51,6 +51,9 @@ public class AthleteResource {
|
|||||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||||
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||||
Athlete athlete = mapToEntity(dto);
|
Athlete athlete = mapToEntity(dto);
|
||||||
|
if(athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(mapToDTO(athleteDAO.findByKeycloakId(athlete.getKeycloakId()).get()));
|
||||||
|
}
|
||||||
athleteDAO.save(athlete);
|
athleteDAO.save(athlete);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(athlete));
|
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(athlete));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ public class CoachResource {
|
|||||||
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
@PreAuthorize("hasRole('Admin')") // Only admin can create
|
||||||
public ResponseEntity<CoachDTO> create(@RequestBody CoachDTO dto) {
|
public ResponseEntity<CoachDTO> create(@RequestBody CoachDTO dto) {
|
||||||
Coach coach = mapToEntity(dto);
|
Coach coach = mapToEntity(dto);
|
||||||
|
if(coachDAO.existsByKeycloakId(coach.getKeycloakId())) {
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(mapToDTO(coachDAO.findByKeycloakId(coach.getKeycloakId()).get()));
|
||||||
|
}
|
||||||
coachDAO.save(coach);
|
coachDAO.save(coach);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(coach));
|
return ResponseEntity.status(HttpStatus.CREATED).body(mapToDTO(coach));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user