get session de l'user dans edt

This commit is contained in:
trochas
2026-01-10 12:47:08 +01:00
parent fca7362bb7
commit 8d844d2b2f
6 changed files with 68 additions and 23 deletions

View File

@@ -45,7 +45,7 @@ export const athleteService = {
delete: (id: number | string) => api.delete(`/athlete/${id}`), delete: (id: number | string) => api.delete(`/athlete/${id}`),
// session-related endpoints exposed by AthleteResource // session-related endpoints exposed by AthleteResource
getSessionsForAthlete: (athleteId: number | null) => api.get(`/athletes/athlete/${athleteId}/session`), getSessionsForAthlete: (athleteId: number | null) => api.get<SessionDTO[]>(`/athletes/athlete/${athleteId}/session`),
getAllSessions: () => api.get(`/athletes/session`), getAllSessions: () => api.get(`/athletes/session`),
getActivitiesForSession: (sessionId: number | string) => api.get(`/athletes/session/${sessionId}/activities`), getActivitiesForSession: (sessionId: number | string) => api.get(`/athletes/session/${sessionId}/activities`),
getSessionsAfterDate: (athleteId: number | string, date: string) => api.get(`/athletes/${athleteId}/session/after/${encodeURIComponent(date)}`), 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}`), getByKeycloakId: (keycloakId: string) => api.get(`/coach/keycloak/${keycloakId}`),
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data), update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
delete: (id: number | string) => api.delete(`/coach/delete/${id}`), delete: (id: number | string) => api.delete(`/coach/delete/${id}`),
getSessionsForCoach: (coachId: number | null) => api.get(`/coach/${coachId}/session`), getSessionsForCoach: (coachId: number | null) => api.get<SessionDTO[]>(`/coach/${coachId}/session`),
}; };
export const userService = { export const userService = {

View File

@@ -43,8 +43,11 @@ export const CreateSession = () => {
session.activites = activities; session.activites = activities;
session.coach = user; session.coach = user;
await createSessionAPI(session); const newSession = await createSessionAPI(session);
console.log("Session créée"); if(newSession!==null){
console.log("Session créée");
}
else console.error("Erreur lors de la création de la session");
// reset // reset
setName(""); setName("");

View File

@@ -80,8 +80,12 @@ export const EDT =() =>{
async function updateWeek(week:Date){ async function updateWeek(week:Date){
//TODO updateSession //TODO updateSession
await delay(2000); //await delay(2000);
//await updateSessionsOfUser(user,null,null); //await updateSessionsOfUser(user,null,null);
if(user instanceof Athlete || user instanceof Coach){
const newSessions:Session[] = await getSessionsOfUserAPI(user);
user.sessions = newSessions;
}
setLoadedWeek(week); setLoadedWeek(week);
} }

View File

@@ -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<boolean>(false);
function handleOpen(): void {
setOpen(!open);
}
return (
<div>
{/* TODO */}
</div>
)
}
export default ObjectLigne

View File

@@ -8,6 +8,7 @@ import ObjectActivite from "./object/activite";
import ObjectUser from "./object/user"; import ObjectUser from "./object/user";
import { getAllSessionsAPI } from "../requetes"; import { getAllSessionsAPI } from "../requetes";
import { useKeycloak } from "@react-keycloak/web"; import { useKeycloak } from "@react-keycloak/web";
import ObjectLigne from "./object/lignes";
export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes"; export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes";
@@ -32,10 +33,12 @@ import { useKeycloak } from "@react-keycloak/web";
async function updateCoachs() { async function updateCoachs() {
} }
async function updateActivites() {
}
async function updateSessions() { async function updateSessions() {
const sessions:Session[] = await getAllSessionsAPI(); const sessions:Session[] = await getAllSessionsAPI();
setAllSessions(sessions); setAllSessions(sessions);
console.log("GET ALL SESSION ");
} }
async function updateLignes() { async function updateLignes() {
@@ -43,17 +46,21 @@ import { useKeycloak } from "@react-keycloak/web";
useEffect(() => { useEffect(() => {
update();
},[user,value])
function update(){
if(keycloak.authenticated){ if(keycloak.authenticated){
updateSessions(); if(value=="sessions") updateSessions();
{(user instanceof Admin || user instanceof Coach) && if (user instanceof Admin || user instanceof Coach){
updateAthletes(); if(value=="athletes") updateAthletes();
updateCoachs(); if(value=="coachs") updateCoachs();
updateLignes(); if(value=="lignes") updateLignes();
if(value=="activites") updateActivites();
} }
} }
}
},[user])
return ( return (
@@ -81,6 +88,7 @@ import { useKeycloak } from "@react-keycloak/web";
<div className="edt_sessions_panel"> <div className="edt_sessions_panel">
<h3>Liste des {value}</h3> <h3>Liste des {value}</h3>
<button onClick={()=>update()}> Actualiser </button>
<div className="list_object"> <div className="list_object">
{value==="athletes" && ( {value==="athletes" && (
allAthletes.map((athlete) => ( allAthletes.map((athlete) => (
@@ -93,8 +101,8 @@ import { useKeycloak } from "@react-keycloak/web";
)) ))
)} )}
{value==="coachs" && ( {value==="coachs" && (
allSessions.map((session) => ( //TODO allCoachs.map((coach) => (
<ObjectSession session={session}/> <ObjectUser coach={coach}/>
)) ))
)} )}
{value==="sessions" && ( {value==="sessions" && (
@@ -103,8 +111,8 @@ import { useKeycloak } from "@react-keycloak/web";
)) ))
)} )}
{value==="lignes" && ( {value==="lignes" && (
allSessions.map((session) => ( //TODO allLignes.map((ligne) => (
<ObjectSession session={session}/> <ObjectLigne ligne={ligne}/>
)) ))
)} )}
</div> </div>

View File

@@ -272,15 +272,22 @@ export async function getCoachByIdAPI(id:number|null): Promise<Coach|null> {
} }
//SESSION //SESSION
export async function getSessionsOfUserAPI(user:Coach|Athlete){ export async function getSessionsOfUserAPI(user:User): Promise<Session[]>{
try { try {
var sessionsDTO:SessionDTO[] = []
if (user instanceof Coach) { if (user instanceof Coach) {
const response = await coachService.getSessionsForCoach(user.id); //TODO const response = await coachService.getSessionsForCoach(user.id); //TODO
return response.data; sessionsDTO = response.data;
}else if (user instanceof Athlete) { }else if (user instanceof Athlete) {
const response = await athleteService.getSessionsForAthlete(user.id); //TODO 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) { }catch (error) {
console.error("Error fetching sessions for user:", error); console.error("Error fetching sessions for user:", error);
return []; return [];