get session de l'user dans edt
This commit is contained in:
@@ -45,7 +45,7 @@ export const athleteService = {
|
||||
delete: (id: number | string) => api.delete(`/athlete/${id}`),
|
||||
|
||||
// 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`),
|
||||
getActivitiesForSession: (sessionId: number | string) => api.get(`/athletes/session/${sessionId}/activities`),
|
||||
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}`),
|
||||
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
||||
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 = {
|
||||
|
||||
@@ -43,8 +43,11 @@ export const CreateSession = () => {
|
||||
session.activites = activities;
|
||||
session.coach = user;
|
||||
|
||||
await createSessionAPI(session);
|
||||
console.log("Session créée");
|
||||
const newSession = await createSessionAPI(session);
|
||||
if(newSession!==null){
|
||||
console.log("Session créée");
|
||||
}
|
||||
else console.error("Erreur lors de la création de la session");
|
||||
|
||||
// reset
|
||||
setName("");
|
||||
|
||||
@@ -80,8 +80,12 @@ export const EDT =() =>{
|
||||
|
||||
async function updateWeek(week:Date){
|
||||
//TODO updateSession
|
||||
await delay(2000);
|
||||
//await delay(2000);
|
||||
//await updateSessionsOfUser(user,null,null);
|
||||
if(user instanceof Athlete || user instanceof Coach){
|
||||
const newSessions:Session[] = await getSessionsOfUserAPI(user);
|
||||
user.sessions = newSessions;
|
||||
}
|
||||
setLoadedWeek(week);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -8,6 +8,7 @@ import ObjectActivite from "./object/activite";
|
||||
import ObjectUser from "./object/user";
|
||||
import { getAllSessionsAPI } from "../requetes";
|
||||
import { useKeycloak } from "@react-keycloak/web";
|
||||
import ObjectLigne from "./object/lignes";
|
||||
|
||||
|
||||
export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes";
|
||||
@@ -32,10 +33,12 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
async function updateCoachs() {
|
||||
}
|
||||
|
||||
async function updateActivites() {
|
||||
}
|
||||
|
||||
async function updateSessions() {
|
||||
const sessions:Session[] = await getAllSessionsAPI();
|
||||
setAllSessions(sessions);
|
||||
console.log("GET ALL SESSION ");
|
||||
}
|
||||
|
||||
async function updateLignes() {
|
||||
@@ -43,17 +46,21 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(keycloak.authenticated){
|
||||
updateSessions();
|
||||
{(user instanceof Admin || user instanceof Coach) &&
|
||||
updateAthletes();
|
||||
updateCoachs();
|
||||
updateLignes();
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
},[user,value])
|
||||
|
||||
},[user])
|
||||
function update(){
|
||||
if(keycloak.authenticated){
|
||||
if(value=="sessions") updateSessions();
|
||||
if (user instanceof Admin || user instanceof Coach){
|
||||
if(value=="athletes") updateAthletes();
|
||||
if(value=="coachs") updateCoachs();
|
||||
if(value=="lignes") updateLignes();
|
||||
if(value=="activites") updateActivites();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
@@ -81,6 +88,7 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
|
||||
<div className="edt_sessions_panel">
|
||||
<h3>Liste des {value}</h3>
|
||||
<button onClick={()=>update()}> Actualiser </button>
|
||||
<div className="list_object">
|
||||
{value==="athletes" && (
|
||||
allAthletes.map((athlete) => (
|
||||
@@ -93,8 +101,8 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
))
|
||||
)}
|
||||
{value==="coachs" && (
|
||||
allSessions.map((session) => ( //TODO
|
||||
<ObjectSession session={session}/>
|
||||
allCoachs.map((coach) => (
|
||||
<ObjectUser coach={coach}/>
|
||||
))
|
||||
)}
|
||||
{value==="sessions" && (
|
||||
@@ -103,8 +111,8 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
))
|
||||
)}
|
||||
{value==="lignes" && (
|
||||
allSessions.map((session) => ( //TODO
|
||||
<ObjectSession session={session}/>
|
||||
allLignes.map((ligne) => (
|
||||
<ObjectLigne ligne={ligne}/>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -272,15 +272,22 @@ export async function getCoachByIdAPI(id:number|null): Promise<Coach|null> {
|
||||
}
|
||||
|
||||
//SESSION
|
||||
export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
export async function getSessionsOfUserAPI(user:User): Promise<Session[]>{
|
||||
try {
|
||||
var sessionsDTO:SessionDTO[] = []
|
||||
if (user instanceof Coach) {
|
||||
const response = await coachService.getSessionsForCoach(user.id); //TODO
|
||||
return response.data;
|
||||
sessionsDTO = response.data;
|
||||
}else if (user instanceof Athlete) {
|
||||
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) {
|
||||
console.error("Error fetching sessions for user:", error);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user