diff --git a/front_end/src/api.ts b/front_end/src/api.ts index b1a3816..a7d0649 100644 --- a/front_end/src/api.ts +++ b/front_end/src/api.ts @@ -2,7 +2,7 @@ import axios from "axios"; import keycloak from "./keycloak"; import { get } from "http"; -import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO"; +import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO"; const api = axios.create({ @@ -65,7 +65,7 @@ export const activiteService = { export const sessionService = { // controller uses singular /session/* endpoints create: (data: any) => api.post(`/session/create`, data), - getAll: () => api.get(`/session/all`), + getAll: () => api.get(`/session/all`), getById: (id: number | string) => api.get(`/session/${id}`), delete: (id: number | string) => api.delete(`/session/delete/${id}`), update: (id: number | string, data: any) => api.put(`/session/update/${id}`, data), diff --git a/front_end/src/components/ressourcePanel.tsx b/front_end/src/components/ressourcePanel.tsx index 58cd120..c54aa2c 100644 --- a/front_end/src/components/ressourcePanel.tsx +++ b/front_end/src/components/ressourcePanel.tsx @@ -19,10 +19,10 @@ import { useKeycloak } from "@react-keycloak/web"; const [value,setValue] = useState("sessions"); const[allAthletes,setAllAthletes] = useState([]); + const[allActivites,setAllActivites] = useState([]); const[allCoachs,setAllCoachs] = useState([]); const[allSessions,setAllSessions] = useState([]); const[allLignes,setAllLignes] = useState([]); - const[allActivites,setAllActivites] = useState([]); async function updateAthletes() { @@ -34,6 +34,8 @@ import { useKeycloak } from "@react-keycloak/web"; async function updateSessions() { const sessions:Session[] = await getAllSessionsAPI(); + setAllSessions(sessions); + console.log("GET ALL SESSION "); } async function updateLignes() { @@ -86,7 +88,7 @@ import { useKeycloak } from "@react-keycloak/web"; )) )} {value==="activites" && ( - allActivites.map((activite) => ( + allActivites.map(activite => ( )) )} diff --git a/front_end/src/requetes.tsx b/front_end/src/requetes.tsx index c3cbb59..c114d61 100644 --- a/front_end/src/requetes.tsx +++ b/front_end/src/requetes.tsx @@ -199,6 +199,16 @@ export async function getAllUserAPI(): Promise { } } +export async function getCoachByIdAPI(id:number): Promise { + try{ + const response = await coachService.getById(id); + return new Coach(response.data); + }catch (error) { + console.error("Error fetching coach by id:", error); + return null; + } +} + //SESSION export async function getSessionsOfUserAPI(user:Coach|Athlete){ try { @@ -218,7 +228,19 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){ export async function getAllSessionsAPI():Promise{ try { const response = await sessionService.getAll(); - return response.data; + const sessions = await Promise.all( + response.data.map(async sessionDTO => { + const session = new Session(sessionDTO); + const coach = await getCoachByIdAPI(sessionDTO.coachId); + + if (coach != null) { + session.coach = coach; + } + return session; + }) + ); + + return sessions; } catch (error) { console.error("Error fetching sessions:", error); throw error;