ressourcePanel getAll

This commit is contained in:
trochas
2026-01-10 17:38:40 +01:00
parent 9aeef08e65
commit e85f76c810
3 changed files with 36 additions and 8 deletions

View File

@@ -38,7 +38,7 @@ export function clearAuthToken() {
export const athleteService = {
// controller is mounted at /athlete
create: (data: any) => api.post<AthleteDTO>("/athlete/create", data),
getAll: () => api.get("/athlete/all"),
getAll: () => api.get<AthleteDTO[]>("/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<ActiviteDTO[]>(`/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<CoachDTO>(`/coach/create`, data),
getAll: () => api.get(`/coach/all`),
getAll: () => api.get<CoachDTO[]>(`/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),

View File

@@ -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() {

View File

@@ -189,6 +189,21 @@ export async function createActivityAPI(activity: Activite):Promise<Activite>{
}
}
export async function getAllActiviteAPI(): Promise<Activite[]> {
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<Athlete>{
try {
const response = await api.post<Athlete>("/athlete/create/",athlete.toDTO);
@@ -319,9 +334,12 @@ export async function getAllSessionsAPI():Promise<Session[]>{
//COACH
export async function getAllCoach(): Promise<Coach[]> {
try {
const response = await api.get<Coach[]>("/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<Coach[]> {
export async function getAllAthlete(): Promise<Athlete[]> {
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;