From e85f76c810b1b708f7c118cdf22ab4ceee3e52eb Mon Sep 17 00:00:00 2001 From: trochas Date: Sat, 10 Jan 2026 17:38:40 +0100 Subject: [PATCH] ressourcePanel getAll --- front_end/src/api.ts | 6 ++--- front_end/src/components/ressourcePanel.tsx | 8 +++++- front_end/src/requetes.tsx | 30 ++++++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/front_end/src/api.ts b/front_end/src/api.ts index da4b445..b57e12c 100644 --- a/front_end/src/api.ts +++ b/front_end/src/api.ts @@ -38,7 +38,7 @@ export function clearAuthToken() { export const athleteService = { // controller is mounted at /athlete create: (data: any) => api.post("/athlete/create", data), - getAll: () => api.get("/athlete/all"), + getAll: () => api.get("/athlete/all"), getById: (id: number | string) => api.get(`/athlete/${id}`), getByKeycloakId: (keycloakId: string) => api.get(`/athlete/keycloak/${encodeURIComponent(keycloakId)}`), update: (id: number | string, data: any) => api.put(`/athlete/${id}`, data), @@ -58,7 +58,7 @@ export const activiteService = { delete: (id: number | string) => api.delete(`/activite/delete/${id}`), update: (id: number | string, data: ActiviteDTO) => api.post(`/activite/update/${id}`, data), getById: (id: number | string) => api.get(`/activite/${id}`), - getAll: () => api.get(`/activite/all`), + getAll: () => api.get(`/activite/all`), getByTheme: (theme: string) => api.get(`/activite/theme/${encodeURIComponent(theme)}`), getDataActivite: (id: number | string) => api.get(`/activite/${id}`), }; @@ -80,7 +80,7 @@ export const sessionService = { export const coachService = { // controller doesn't declare a class-level path consistently; support both common patterns create: (data: any) => api.post(`/coach/create`, data), - getAll: () => api.get(`/coach/all`), + getAll: () => api.get(`/coach/all`), getById: (id: number) => api.get(`/coach/${id}`), getByKeycloakId: (keycloakId: string) => api.get(`/coach/keycloak/${keycloakId}`), update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data), diff --git a/front_end/src/components/ressourcePanel.tsx b/front_end/src/components/ressourcePanel.tsx index 67d36a6..785423e 100644 --- a/front_end/src/components/ressourcePanel.tsx +++ b/front_end/src/components/ressourcePanel.tsx @@ -6,7 +6,7 @@ import { keyboard } from "@testing-library/user-event/dist/keyboard"; import ObjectSession from "./object/session"; import ObjectActivite from "./object/activite"; import ObjectUser from "./object/user"; -import { getAllSessionsAPI } from "../requetes"; +import { getAllActiviteAPI, getAllAthlete, getAllCoach, getAllSessionsAPI } from "../requetes"; import { useKeycloak } from "@react-keycloak/web"; import ObjectLigne from "./object/lignes"; @@ -27,13 +27,19 @@ import ObjectLigne from "./object/lignes"; async function updateAthletes() { + const athletes:Athlete[] = await getAllAthlete(); + setAllAthletes(athletes); } async function updateCoachs() { + const coachs:Coach[] = await getAllCoach(); + setAllCoachs(coachs); } async function updateActivites() { + const activites:Activite[] = await getAllActiviteAPI(); + setAllActivites(activites); } async function updateSessions() { diff --git a/front_end/src/requetes.tsx b/front_end/src/requetes.tsx index d1a7098..e36b6f2 100644 --- a/front_end/src/requetes.tsx +++ b/front_end/src/requetes.tsx @@ -189,6 +189,21 @@ export async function createActivityAPI(activity: Activite):Promise{ } } +export async function getAllActiviteAPI(): Promise { + try { + const response = await activiteService.getAll(); + const activites:Activite[] = [] + response.data.forEach(dto => { + activites.push(new Activite(dto)); + }); + return activites; + } catch (error) { + console.error("Error fetching users:", error); + throw error; + } +} + + export async function postAthlete(athlete: Athlete):Promise{ try { const response = await api.post("/athlete/create/",athlete.toDTO); @@ -319,9 +334,12 @@ export async function getAllSessionsAPI():Promise{ //COACH export async function getAllCoach(): Promise { try { - const response = await api.get("/coach/all"); - console.log(response); - return response.data; + const response = await coachService.getAll(); + const coachs:Coach[] = [] + response.data.forEach(dto => { + coachs.push(new Coach(dto)); + }); + return coachs; } catch (error) { console.error("Error fetching coachs:", error); throw error; @@ -332,7 +350,11 @@ export async function getAllCoach(): Promise { export async function getAllAthlete(): Promise { try { const response = await athleteService.getAll(); - return response.data; + const athletes:Athlete[] = [] + response.data.forEach(dto => { + athletes.push(new Athlete(dto)); + }); + return athletes; } catch (error) { console.error("Error fetching users:", error); throw error;