Added Keycloak related endpoints and other ones
This commit is contained in:
@@ -165,7 +165,6 @@ public class ActiviteResource {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Activite mapToEntity(ActiviteDTO dto) {
|
||||
Activite activite = new Activite();
|
||||
//ID géré par Postgre ?
|
||||
|
||||
@@ -81,6 +81,13 @@ public class AthleteResource {
|
||||
return ResponseEntity.ok(mapToDTO(athlete));
|
||||
}
|
||||
|
||||
@GetMapping("/keycloak/{keycloak_id}")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<AthleteDTO> getByKeycloakId(@PathVariable String keycloak_id) {
|
||||
Athlete athlete = athleteDAO.findByKeycloakId(keycloak_id).get();
|
||||
return ResponseEntity.ok(mapToDTO(athlete));
|
||||
}
|
||||
|
||||
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||
|
||||
@@ -39,14 +39,22 @@ public class CoachResource {
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@GetMapping("/{keycloak_id}")
|
||||
@GetMapping("/keycloak/{keycloak_id}")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||
public CoachDTO getById(@PathVariable String keycloak_id) {
|
||||
public CoachDTO getByKeycloakId(@PathVariable String keycloak_id) {
|
||||
Coach coach = coachDAO.findByKeycloakId(keycloak_id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
return mapToDTO(coach);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||
public CoachDTO getById(@PathVariable Integer id) {
|
||||
Coach coach = coachDAO.findById(id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
return mapToDTO(coach);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@PreAuthorize("hasRole('Admin')")
|
||||
public ResponseEntity<CoachDTO> update(@PathVariable Integer id, @RequestBody CoachDTO dto) {
|
||||
@@ -59,6 +67,15 @@ public class CoachResource {
|
||||
return ResponseEntity.ok(updatedDto);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/session")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||
public ResponseEntity<List<?>> getSessionsForCoach(@PathVariable Integer id) {
|
||||
Coach coach = coachDAO.findById(id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
List<?> sessions = coach.getSessions();
|
||||
return ResponseEntity.ok(sessions);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@PreAuthorize("hasRole('Admin')")
|
||||
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
||||
|
||||
@@ -59,6 +59,13 @@ public class UserResource {
|
||||
return ResponseEntity.ok(mapToDTO(user));
|
||||
}
|
||||
|
||||
@GetMapping("/keycloak/{keycloak_id}")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<UserDTO> getByKeycloakId(@PathVariable String keycloak_id) {
|
||||
User user = userDAO.findByKeycloakId(keycloak_id).get();
|
||||
return ResponseEntity.ok(mapToDTO(user));
|
||||
}
|
||||
|
||||
private UserDTO mapToDTO(User user) {
|
||||
UserDTO dto = new UserDTO();
|
||||
dto.setId(user.getId());
|
||||
|
||||
Reference in New Issue
Block a user