pages + correction coach dans detail Session
This commit is contained in:
@@ -162,15 +162,15 @@ 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/{athleteId}/session")
|
||||
@GetMapping("/{athleteId}/session")
|
||||
public List<SessionDTO> getSessionsAthlete(@PathVariable Integer athleteId) {
|
||||
// return pet
|
||||
System.out.println("ID A CHERCHER" + athleteId);
|
||||
java.util.Optional<Athlete> j = athleteDAO.findById(athleteId);
|
||||
java.util.Optional<Athlete> athlete = athleteDAO.findById(athleteId);
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
List<SessionDTO> athleteSessions = new ArrayList<>();
|
||||
for (Session s : sessions) {
|
||||
if (s.getAthletes().contains(j.get())) {
|
||||
if (s.getAthletes().contains(athlete.get())) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
|
||||
dto.setId(s.getId());
|
||||
@@ -186,8 +186,8 @@ public class AthleteResource {
|
||||
dto.setGroupe(s.getGroupe());
|
||||
dto.setIsRecurrent(s.getIsRecurrent());
|
||||
List<Integer> athleteIds = new ArrayList<>();
|
||||
for (Athlete athlete : s.getAthletes()) {
|
||||
athleteIds.add(athlete.getId());
|
||||
for (Athlete athlete2 : s.getAthletes()) {
|
||||
athleteIds.add(athlete2.getId());
|
||||
}
|
||||
dto.setAthleteIds(athleteIds);
|
||||
|
||||
@@ -195,7 +195,7 @@ public class AthleteResource {
|
||||
athleteSessions.add(dto);
|
||||
}
|
||||
}
|
||||
System.out.println(j);
|
||||
System.out.println(athlete);
|
||||
return athleteSessions;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package hackathon.FrisbYEE.rest;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.dto.CoachDTO;
|
||||
import hackathon.FrisbYEE.jpa.dto.SessionDTO;
|
||||
import hackathon.FrisbYEE.jpa.metier.Activite;
|
||||
import hackathon.FrisbYEE.jpa.metier.Admin;
|
||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||
import hackathon.FrisbYEE.jpa.metier.Coach;
|
||||
import hackathon.FrisbYEE.jpa.metier.Session;
|
||||
import hackathon.FrisbYEE.jpa.service.CoachDAO;
|
||||
import hackathon.FrisbYEE.jpa.service.SessionDAO;
|
||||
import hackathon.FrisbYEE.jpa.service.UserDAO;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,6 +30,8 @@ public class CoachResource {
|
||||
private CoachDAO coachDAO;
|
||||
@Autowired
|
||||
private UserDAO userDAO;
|
||||
@Autowired
|
||||
private SessionDAO sessionDAO;
|
||||
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasRole('admin') or hasRole('coach')") // Only admin can create
|
||||
@@ -88,11 +95,38 @@ public class CoachResource {
|
||||
|
||||
@GetMapping("/{id}/session")
|
||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||
public ResponseEntity<List<?>> getSessionsForCoach(@PathVariable Integer id) {
|
||||
public ResponseEntity<List<SessionDTO>> getSessionsForCoach(@PathVariable Integer id) {
|
||||
Coach coach = coachDAO.findById(id)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||
List<?> sessions = coach.getSessions();
|
||||
return ResponseEntity.ok(sessions);
|
||||
List<Session> sessions = sessionDAO.findAll();
|
||||
List<SessionDTO> coachSessions = new ArrayList<>();
|
||||
for (Session s : sessions) {
|
||||
if (s.getCoach().equals(coach)) {
|
||||
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
|
||||
coachSessions.add(dto);
|
||||
}
|
||||
}
|
||||
return ResponseEntity.ok(coachSessions);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package hackathon.FrisbYEE.rest;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.dto.ActiviteDTO;
|
||||
import hackathon.FrisbYEE.jpa.dto.CoachDTO;
|
||||
import hackathon.FrisbYEE.jpa.dto.SessionDTO;
|
||||
import hackathon.FrisbYEE.jpa.metier.Activite;
|
||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||
@@ -170,6 +171,29 @@ public class SessionResource {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/coach")
|
||||
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||
public ResponseEntity<CoachDTO> getCoachBySessionId(@PathVariable Integer id) {
|
||||
try {
|
||||
Session session = sessionDAO.findById(id).orElseThrow();
|
||||
Coach coach = session.getCoach();
|
||||
|
||||
CoachDTO dto = new CoachDTO();
|
||||
dto.setId(coach.getId());
|
||||
dto.setName(coach.getName());
|
||||
dto.setPrenom(coach.getPrenom());
|
||||
List<Integer> listSession = new ArrayList<Integer>();
|
||||
for (Session s : coach.getSessions()) {
|
||||
listSession.add(session.getId());
|
||||
}
|
||||
dto.setSessionIds(listSession);
|
||||
|
||||
return ResponseEntity.ok(dto);
|
||||
} catch (Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new CoachDTO());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/{id}/activities")
|
||||
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||
|
||||
Reference in New Issue
Block a user