subscribe + unsubscribe + edt
This commit is contained in:
@@ -40,6 +40,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
public class AthleteResource {
|
||||
@Autowired
|
||||
private AthleteDAO athleteDAO;
|
||||
@Autowired
|
||||
private SessionDAO sessionDAO;
|
||||
|
||||
@Operation(summary = "Crée un Athlète avec les informations fournies")
|
||||
@@ -161,7 +162,7 @@ public class AthleteResource {
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class)))
|
||||
})
|
||||
@GetMapping("/athlete/{id}/session")
|
||||
@GetMapping("/athlete/{athleteId}/session")
|
||||
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
||||
// return pet
|
||||
System.out.println("ID A CHERCHER" + athleteId);
|
||||
@@ -171,7 +172,25 @@ public class AthleteResource {
|
||||
for (Session s : sessions) {
|
||||
if (s.getAthletes().contains(j.get())) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
|
||||
dto.setId(s.getId());
|
||||
dto.setName(s.getName());
|
||||
dto.setCreneau(s.getCreneau());
|
||||
List<Integer> activiteIDs = new ArrayList<>();
|
||||
for (Activite activite : s.getActivites()) {
|
||||
activiteIDs.add(activite.getId());
|
||||
}
|
||||
dto.setActiviteIds(activiteIDs);
|
||||
dto.setCoachId(s.getCoach().getId());
|
||||
dto.setDuree(s.getDuree());
|
||||
dto.setGroupe(s.getGroupe());
|
||||
dto.setIsRecurrent(s.getIsRecurrent());
|
||||
List<Integer> athleteIds = new ArrayList<>();
|
||||
for (Athlete athlete : s.getAthletes()) {
|
||||
athleteIds.add(athlete.getId());
|
||||
}
|
||||
dto.setAthleteIds(athleteIds);
|
||||
|
||||
// Map other fields as necessary
|
||||
athleteSessions.add(dto);
|
||||
}
|
||||
|
||||
@@ -114,6 +114,38 @@ 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){
|
||||
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){
|
||||
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