change endpoints

This commit is contained in:
tuanvu
2026-01-09 10:46:12 +01:00
parent dc814d4a7b
commit 46396d035b
4 changed files with 32 additions and 90 deletions

View File

@@ -2,6 +2,7 @@ import api, { activiteService, athleteService, coachService, sessionService } fr
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
import Keycloak from 'keycloak-js'
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
import { useLocalData } from "./context/useLocalData";
//debug:
export function delay(ms: number): Promise<void> {
@@ -45,24 +46,6 @@ export async function getUser(keycloak:Keycloak): Promise<User|null>{
}
}
/*
retourne toutes les Session dont l'user est inscrit
*/
export async function updateSessionsOfUserAPI(user:Coach|Athlete, min: Date|null, max: Date|null){
try {
const response = await api.get<Session[]>(`/users/${user.id}/sessions`, {
params: {
minDate: min ? min.toISOString() : undefined,
maxDate: max ? max.toISOString() : undefined
}
});
return response.data;
} catch (error) {
console.error("Error fetching sessions for user:", error);
return [];
}
}
export async function updateActivitiesOfSessionAPI(session:Session){
try {
const response = await api.get<Activite[]>(`/sessions/${session.id}/activities`);
@@ -95,10 +78,6 @@ export async function unsubscribeSessionAPI(user:User, session:Session):Promise<
// ADMIN :
export async function updateAllSessionAPI(min: Date, max: Date){
//TODO
}
export async function updateAllUserAPI(){
}
@@ -193,26 +172,27 @@ export async function setSessionCreneauAPI(session: Session, date:Date){
}
export async function getSessionsAPI(): Promise<Session[]> {
//GET /////////////////////////////////////////////////////////
//SESSION
export async function getSessionsOfUserAPI(user:Coach|Athlete){
try {
const response = await api.get<Session[]>("/session");
return response.data;
} catch (error) {
console.error("Error fetching sessions:", error);
throw error;
}
}
export async function getUsersAPI(): Promise<User[]> {
try {
const response = await api.get<User[]>("/coach/all");
return response.data;
} catch (error) {
console.error("Error fetching users:", error);
throw error;
if (user instanceof Coach) {
const response = await coachService.getSessionsForCoach(user.id); //TODO
return response.data;
}else if (user instanceof Athlete) {
const response = await athleteService.getSessionsForAthlete(user.id); //TODO
return response.data;
}
}catch (error) {
console.error("Error fetching sessions for user:", error);
return [];
}
}
export async function getCoachsAPI(): Promise<Coach[]> {
//COACH
export async function getAllCoach(): Promise<Coach[]> {
try {
const response = await api.get<Coach[]>("/coach/all");
console.log(response);
@@ -221,4 +201,16 @@ export async function getCoachsAPI(): Promise<Coach[]> {
console.error("Error fetching coachs:", error);
throw error;
}
}
}
//ATHLETE
export async function getAllAthlete(): Promise<Athlete[]> {
try {
const response = await athleteService.getAll();
return response.data;
} catch (error) {
console.error("Error fetching users:", error);
throw error;
}
}