diff --git a/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java index 5ec326f..a2f7fa0 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java @@ -44,7 +44,7 @@ public class SessionResource { @PreAuthorize("hasRole('coach')") public ResponseEntity create(@RequestBody SessionDTO dto) { try { - if(sessionDAO.findById(dto.getId()).isPresent()) { + if (sessionDAO.findById(dto.getId()).isPresent()) { return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + dto.getId() + " already exists."); } @@ -114,17 +114,34 @@ public class SessionResource { return ResponseEntity.noContent().build(); } - //Commented because not finished + @GetMapping("/{id}/activities") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") + public ResponseEntity getActivitiesBySessionId(@PathVariable Integer id) { + try { + Session session = sessionDAO.findById(id).orElseThrow(); + List activites = session.getActivites(); + List activiteDTOs = new ArrayList<>(); + for (Activite activite : activites) { + ActiviteDTO dto = new ActiviteDTO(); + dto.setId(activite.getId()); + dto.setName(activite.getName()); + activiteDTOs.add(dto); + } + return ResponseEntity.ok(activiteDTOs); + } catch (Exception ex) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage()); + } + } @GetMapping("/{id_session}/activities/add/{id_act}") @PreAuthorize("hasRole('coach') or hasRole('admin')") public ResponseEntity addActivity(@PathVariable Integer id_sess, @PathVariable Integer id_act) { Session s = sessionDAO.findById(id_sess).get(); - if(s.equals(null)){ + if (s.equals(null)) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Session not found"); } Activite a = activiteDAO.findById(id_act).get(); - if(a.equals(null)){ + if (a.equals(null)) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Activite not found"); } List l = s.getActivites(); @@ -167,13 +184,13 @@ public class SessionResource { private Session maptoEntity(SessionDTO dto) { Session session = new Session(); - System.out.println("ID "+ session.getId()); + System.out.println("ID " + session.getId()); session.setName(dto.getName()); session.setIsRecurrent(dto.getIsRecurrent()); session.setCreneau(dto.getCreneau()); session.setDuree(dto.getDuree()); session.setGroupe(dto.getGroupe()); - + return session; } } diff --git a/front_end/src/components/ressourceList.tsx b/front_end/src/components/ressourceList.tsx index a11730f..29a33d7 100644 --- a/front_end/src/components/ressourceList.tsx +++ b/front_end/src/components/ressourceList.tsx @@ -4,17 +4,12 @@ import ObjectSession from "./object/session"; import {calculStatsAthlete, niveauAlerte} from "../utils/athleteUtils"; import {calculTempsDeJeuParLigne} from "../utils/ligneUtils"; import ObjectActivite from "./object/activite"; - - type AthleteListProps = { athletes: Athlete[], sessions: Session[]}; type ActiviteListProps = { activites: Activite[] }; type CoachListProps = { coachs: Coach[] }; type SessionListProps = { sessions: Session[]}; type LigneListProps = { lignes: Ligne[], tempsDeJeuParLigne: Map }; - - - function AthleteList({ athletes, sessions }: AthleteListProps) { const [dateDebut, setDateDebut] = React.useState(new Date()); const [dateFin, setDateFin] = React.useState(new Date());