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