From 8d844d2b2f0d951ac8f58b3124a3e6c7de5f2e8d Mon Sep 17 00:00:00 2001 From: trochas Date: Sat, 10 Jan 2026 12:47:08 +0100 Subject: [PATCH] get session de l'user dans edt --- front_end/src/api.ts | 4 +-- front_end/src/components/createSession.tsx | 7 ++-- front_end/src/components/edt.tsx | 6 +++- front_end/src/components/object/lignes.tsx | 23 +++++++++++++ front_end/src/components/ressourcePanel.tsx | 38 +++++++++++++-------- front_end/src/requetes.tsx | 13 +++++-- 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/front_end/src/api.ts b/front_end/src/api.ts index 9b4ad47..1282c72 100644 --- a/front_end/src/api.ts +++ b/front_end/src/api.ts @@ -45,7 +45,7 @@ export const athleteService = { delete: (id: number | string) => api.delete(`/athlete/${id}`), // session-related endpoints exposed by AthleteResource - getSessionsForAthlete: (athleteId: number | null) => api.get(`/athletes/athlete/${athleteId}/session`), + getSessionsForAthlete: (athleteId: number | null) => api.get(`/athletes/athlete/${athleteId}/session`), getAllSessions: () => api.get(`/athletes/session`), getActivitiesForSession: (sessionId: number | string) => api.get(`/athletes/session/${sessionId}/activities`), getSessionsAfterDate: (athleteId: number | string, date: string) => api.get(`/athletes/${athleteId}/session/after/${encodeURIComponent(date)}`), @@ -85,7 +85,7 @@ export const coachService = { getByKeycloakId: (keycloakId: string) => api.get(`/coach/keycloak/${keycloakId}`), update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data), delete: (id: number | string) => api.delete(`/coach/delete/${id}`), - getSessionsForCoach: (coachId: number | null) => api.get(`/coach/${coachId}/session`), + getSessionsForCoach: (coachId: number | null) => api.get(`/coach/${coachId}/session`), }; export const userService = { diff --git a/front_end/src/components/createSession.tsx b/front_end/src/components/createSession.tsx index 9a0f60c..74fb4a7 100644 --- a/front_end/src/components/createSession.tsx +++ b/front_end/src/components/createSession.tsx @@ -43,8 +43,11 @@ export const CreateSession = () => { session.activites = activities; session.coach = user; - await createSessionAPI(session); - console.log("Session créée"); + const newSession = await createSessionAPI(session); + if(newSession!==null){ + console.log("Session créée"); + } + else console.error("Erreur lors de la création de la session"); // reset setName(""); diff --git a/front_end/src/components/edt.tsx b/front_end/src/components/edt.tsx index 4ed0d31..281ddcb 100644 --- a/front_end/src/components/edt.tsx +++ b/front_end/src/components/edt.tsx @@ -80,8 +80,12 @@ export const EDT =() =>{ async function updateWeek(week:Date){ //TODO updateSession - await delay(2000); + //await delay(2000); //await updateSessionsOfUser(user,null,null); + if(user instanceof Athlete || user instanceof Coach){ + const newSessions:Session[] = await getSessionsOfUserAPI(user); + user.sessions = newSessions; + } setLoadedWeek(week); } diff --git a/front_end/src/components/object/lignes.tsx b/front_end/src/components/object/lignes.tsx index e69de29..674c430 100644 --- a/front_end/src/components/object/lignes.tsx +++ b/front_end/src/components/object/lignes.tsx @@ -0,0 +1,23 @@ +import { useState } from 'react'; +import { Activite, Ligne } from '../../classes'; +import '../style/objectList.css'; + +type Props = { + ligne: Ligne +} + +function ObjectLigne({ligne}: Props) { + const [open, setOpen] = useState(false); + + function handleOpen(): void { + setOpen(!open); + } + + return ( +
+ {/* TODO */} +
+ ) +} + +export default ObjectLigne \ No newline at end of file diff --git a/front_end/src/components/ressourcePanel.tsx b/front_end/src/components/ressourcePanel.tsx index c54aa2c..67d36a6 100644 --- a/front_end/src/components/ressourcePanel.tsx +++ b/front_end/src/components/ressourcePanel.tsx @@ -8,6 +8,7 @@ import ObjectActivite from "./object/activite"; import ObjectUser from "./object/user"; import { getAllSessionsAPI } from "../requetes"; import { useKeycloak } from "@react-keycloak/web"; +import ObjectLigne from "./object/lignes"; export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes"; @@ -32,10 +33,12 @@ import { useKeycloak } from "@react-keycloak/web"; async function updateCoachs() { } + async function updateActivites() { + } + async function updateSessions() { const sessions:Session[] = await getAllSessionsAPI(); setAllSessions(sessions); - console.log("GET ALL SESSION "); } async function updateLignes() { @@ -43,17 +46,21 @@ import { useKeycloak } from "@react-keycloak/web"; useEffect(() => { - if(keycloak.authenticated){ - updateSessions(); - {(user instanceof Admin || user instanceof Coach) && - updateAthletes(); - updateCoachs(); - updateLignes(); - } - } - + update(); + },[user,value]) - },[user]) + function update(){ + if(keycloak.authenticated){ + if(value=="sessions") updateSessions(); + if (user instanceof Admin || user instanceof Coach){ + if(value=="athletes") updateAthletes(); + if(value=="coachs") updateCoachs(); + if(value=="lignes") updateLignes(); + if(value=="activites") updateActivites(); + } + + } + } return ( @@ -81,6 +88,7 @@ import { useKeycloak } from "@react-keycloak/web";

Liste des {value}

+
{value==="athletes" && ( allAthletes.map((athlete) => ( @@ -93,8 +101,8 @@ import { useKeycloak } from "@react-keycloak/web"; )) )} {value==="coachs" && ( - allSessions.map((session) => ( //TODO - + allCoachs.map((coach) => ( + )) )} {value==="sessions" && ( @@ -103,8 +111,8 @@ import { useKeycloak } from "@react-keycloak/web"; )) )} {value==="lignes" && ( - allSessions.map((session) => ( //TODO - + allLignes.map((ligne) => ( + )) )}
diff --git a/front_end/src/requetes.tsx b/front_end/src/requetes.tsx index 2c44b83..a204c49 100644 --- a/front_end/src/requetes.tsx +++ b/front_end/src/requetes.tsx @@ -272,15 +272,22 @@ export async function getCoachByIdAPI(id:number|null): Promise { } //SESSION -export async function getSessionsOfUserAPI(user:Coach|Athlete){ +export async function getSessionsOfUserAPI(user:User): Promise{ try { + var sessionsDTO:SessionDTO[] = [] if (user instanceof Coach) { const response = await coachService.getSessionsForCoach(user.id); //TODO - return response.data; + sessionsDTO = response.data; }else if (user instanceof Athlete) { const response = await athleteService.getSessionsForAthlete(user.id); //TODO - return response.data; + sessionsDTO = response.data; } + const sessions:Session[] = []; + sessionsDTO.forEach(sessionDTO => { + sessions.push(new Session(sessionDTO)); + }); + return sessions; + }catch (error) { console.error("Error fetching sessions for user:", error); return [];