Coaches and Athletes by keycloak id
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package hackathon.FrisbYEE.jpa.service;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.metier.Coach;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CoachDAO extends JpaRepository<Coach, Integer> {
|
||||
|
||||
boolean existsByKeycloakId(String keycloakId);
|
||||
Optional<Coach> findByKeycloakId(String keycloakId);
|
||||
}
|
||||
@@ -76,10 +76,9 @@ public class AthleteResource {
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<AthleteDTO> getById(@PathVariable Integer id) {
|
||||
return athleteDAO.findById(id)
|
||||
.map(athlete -> ResponseEntity.ok(mapToDTO(athlete)))
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
public ResponseEntity<AthleteDTO> getById(@PathVariable String id) {
|
||||
Athlete athlete = athleteDAO.findByKeycloakId(id).get();
|
||||
return ResponseEntity.ok(mapToDTO(athlete));
|
||||
}
|
||||
|
||||
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
||||
|
||||
@@ -39,10 +39,10 @@ public class CoachResource {
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@GetMapping("/{keycloak_id}")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||
public CoachDTO getById(@PathVariable Integer id) {
|
||||
Coach coach = coachDAO.findById(id)
|
||||
public CoachDTO getById(@PathVariable String keycloak_id) {
|
||||
Coach coach = coachDAO.findByKeycloakId(keycloak_id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
return mapToDTO(coach);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user