add getGroupe dans session et athlete

This commit is contained in:
tuanvu
2026-01-12 08:48:07 +01:00
parent 70d6f9b01b
commit 8c56880964
3 changed files with 28 additions and 1 deletions

View File

@@ -208,6 +208,20 @@ public class AthleteResource {
return athleteSessions;
}
@GetMapping("/{athleteId}/groupes")
public List<String> getGroupesByAthlete(@PathVariable Integer athleteId) {
java.util.Optional<Athlete> athleteOptional = athleteDAO.findById(athleteId);
List<String> groupes = new ArrayList<>();
if (athleteOptional.isPresent()) {
Athlete athlete = athleteOptional.get();
for (Session session : athlete.getSessions()) {
if (!groupes.contains(session.getGroupe())) {
groupes.add(session.getGroupe());
}
}
}
return groupes;
}
@Operation(summary = "Récupère toutes les sessions")
@ApiResponses(value = {

View File

@@ -124,6 +124,17 @@ public class SessionResource {
}
}
@GetMapping("{id}/groupe")
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
public ResponseEntity<?> getGroupeById(@PathVariable Integer id) {
try {
Session session = sessionDAO.findById(id).orElseThrow();
return ResponseEntity.ok(session.getGroupe());
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage());
}
}
@PutMapping("/update/{id}")
@PreAuthorize("hasRole('coach')")
public ResponseEntity<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {