add getGroupe dans session et athlete
This commit is contained in:
@@ -51,8 +51,9 @@ public class AthleteResource {
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||
Athlete athlete = mapToEntity(dto);
|
||||
if(athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
||||
return ResponseEntity.status(200).body(mapToDTO(athleteDAO.findByKeycloakId(athlete.getKeycloakId()).get()));
|
||||
if (athleteDAO.existsByKeycloakId(athlete.getKeycloakId())) {
|
||||
return ResponseEntity.status(200)
|
||||
.body(mapToDTO(athleteDAO.findByKeycloakId(athlete.getKeycloakId()).get()));
|
||||
}
|
||||
athleteDAO.save(athlete);
|
||||
return ResponseEntity.status(201).body(mapToDTO(athlete));
|
||||
@@ -177,7 +178,7 @@ public class AthleteResource {
|
||||
dto.setName(s.getName());
|
||||
dto.setCreneau(s.getCreneau());
|
||||
List<Integer> activiteIDs = new ArrayList<>();
|
||||
for (Activite activite : s.getActivites()) {
|
||||
for (Activite activite : s.getActivites()) {
|
||||
activiteIDs.add(activite.getId());
|
||||
}
|
||||
dto.setActiviteIds(activiteIDs);
|
||||
@@ -186,11 +187,11 @@ public class AthleteResource {
|
||||
dto.setGroupe(s.getGroupe());
|
||||
dto.setIsRecurrent(s.getIsRecurrent());
|
||||
List<Integer> athleteIds = new ArrayList<>();
|
||||
for (Athlete athlete : s.getAthletes()) {
|
||||
for (Athlete athlete : s.getAthletes()) {
|
||||
athleteIds.add(athlete.getId());
|
||||
}
|
||||
dto.setAthleteIds(athleteIds);
|
||||
|
||||
|
||||
// Map other fields as necessary
|
||||
athleteSessions.add(dto);
|
||||
}
|
||||
@@ -300,5 +301,18 @@ public class AthleteResource {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,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());
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasRole('coach')")
|
||||
@@ -114,38 +125,34 @@ public class SessionResource {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
@PutMapping("/{id}/subscribe/{userId}")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<Void> subscribe(@PathVariable Integer id,@PathVariable Integer userId){
|
||||
public ResponseEntity<Void> subscribe(@PathVariable Integer id, @PathVariable Integer userId) {
|
||||
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
||||
Athlete athlete = athleteDAO.findById(userId).orElseThrow(() -> new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Athlete not found with id " + userId));
|
||||
|
||||
|
||||
session.getAthletes().add(athlete);
|
||||
sessionDAO.save(session);
|
||||
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PutMapping("/{id}/unsubscribe/{userId}")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<Void> unsubscribe(@PathVariable Integer id,@PathVariable Integer userId){
|
||||
public ResponseEntity<Void> unsubscribe(@PathVariable Integer id, @PathVariable Integer userId) {
|
||||
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
||||
Athlete athlete = athleteDAO.findById(userId).orElseThrow(() -> new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Athlete not found with id " + userId));
|
||||
|
||||
|
||||
session.getAthletes().remove(athlete);
|
||||
sessionDAO.save(session);
|
||||
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}/activities")
|
||||
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<?> getActivitiesBySessionId(@PathVariable Integer id) {
|
||||
|
||||
Reference in New Issue
Block a user