From 39e8be74276292f69bec6bb7fe6e7715ca09a590 Mon Sep 17 00:00:00 2001 From: trochas Date: Fri, 9 Jan 2026 12:58:20 +0100 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20de=20session=20fix=20en=20cours?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front_end/src/api.ts | 4 +- front_end/src/classes.tsx | 29 +++++++- front_end/src/components/createSession.tsx | 18 +++-- front_end/src/components/ressourcePanel.tsx | 80 ++++++++++++++------- front_end/src/requetes.tsx | 14 ++-- 5 files changed, 100 insertions(+), 45 deletions(-) diff --git a/front_end/src/api.ts b/front_end/src/api.ts index b6c6e87..0a57c87 100644 --- a/front_end/src/api.ts +++ b/front_end/src/api.ts @@ -2,7 +2,7 @@ import axios from "axios"; import keycloak from "./keycloak"; import { get } from "http"; -import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO"; +import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO"; const api = axios.create({ @@ -55,7 +55,7 @@ export const athleteService = { export const activiteService = { create: (data: any) => api.post("/activite/create", data), delete: (id: number | string) => api.delete(`/activite/delete/${id}`), - update: (id: number | string, data: any) => api.post(`/activite/update/${id}`, data), + 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`), getByTheme: (theme: string) => api.get(`/activite/theme/${encodeURIComponent(theme)}`), diff --git a/front_end/src/classes.tsx b/front_end/src/classes.tsx index 52266bb..ccfb12e 100644 --- a/front_end/src/classes.tsx +++ b/front_end/src/classes.tsx @@ -118,7 +118,7 @@ export class Session{ name!: string; activitesID: number[] = []; activites: Activite[] = []; - isRecurrent! : Boolean; + isRecurrent! : boolean; creneau!: Date; coach!: Coach; athletesID!: number[] @@ -145,6 +145,21 @@ export class Session{ this.ligne = []; //TODO } + + toDTO():SessionDTO{ + const dto:SessionDTO = { + id: 0, + name: this.name, + isRecurrent: this.isRecurrent, + creneau: this.creneau.toISOString(), + duree: this.duree, + groupe: "", //TODO + coachId: this.coach?.id ?? null, + athleteIds: [], + activiteIds: [] + }; + return dto; + } } export class Activite{ @@ -168,6 +183,18 @@ export class Activite{ } + toDTO():ActiviteDTO{ + const dto:ActiviteDTO = { + id: 0, + name: this.nom, + duree: this.duree, + dataActivite: [], + sessionId: this.session.id, + theme: this.theme + }; + return dto; + } + } /* export function getUserTest():User{ diff --git a/front_end/src/components/createSession.tsx b/front_end/src/components/createSession.tsx index 6bcc9c4..f3eab17 100644 --- a/front_end/src/components/createSession.tsx +++ b/front_end/src/components/createSession.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from "react"; import { Session, User, Coach, Activite, Groupe } from "../classes"; import { useLocalData } from "../context/useLocalData"; import { activiteService, sessionService } from "../api"; -import { postSession } from "../requetes"; +import { createSessionAPI, postSession } from "../requetes"; export const CreateSession = () => { const {user} = useLocalData(); @@ -10,7 +10,7 @@ export const CreateSession = () => { const [activities, setActivities] = useState([]); const [name,setName] = useState(""); const [groupe, setGroupe] = useState(""); - const [creneau, setCreneau] = useState(""); + const [creneau, setCreneau] = useState(new Date()); const [duree, setDuree] = useState(0); const [activiteNom, setActiviteNom] = useState(""); const [activiteTheme, setActiviteTheme] = useState(""); @@ -34,19 +34,25 @@ export const CreateSession = () => { } async function handleCreateSession() { + session.groupe = groupe; + session.creneau = creneau; + session.duree = duree; + session.isRecurrent = isRecurent; + session.activites = activities; - postSession(session); + await createSessionAPI(session); console.log("Session créée"); // reset setName(""); setGroupe(""); - setCreneau(""); + setCreneau(new Date()); setDuree(0); setIsRecurent(false); setActivities([]); - } + setSession(new Session()); + } @@ -62,7 +68,7 @@ export const CreateSession = () => {