diff --git a/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java index 183562d..e25b2d5 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java @@ -44,11 +44,11 @@ public class SessionResource { @PreAuthorize("hasRole('coach')") public ResponseEntity create(@RequestBody SessionDTO dto) { try { - Session session = maptoEntity(dto); - if(sessionDAO.findById(session.getId()).isPresent()) { - return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + session.getId() + " already exists."); + if(sessionDAO.findById(dto.getId()).isPresent()) { + return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + dto.getId() + " already exists."); } + Session session = maptoEntity(dto); Coach c = coachDAO.findById(dto.getCoachId()).orElse(null); session.setCoach(c); sessionDAO.save(session); @@ -161,7 +161,7 @@ public class SessionResource { private Session maptoEntity(SessionDTO dto) { Session session = new Session(); - System.out.println("ID "+ dto.getId()); + System.out.println("ID "+ session.getId()); session.setName(dto.getName()); session.setIsRecurrent(dto.getIsRecurrent()); session.setCreneau(dto.getCreneau()); diff --git a/front_end/src/api.ts b/front_end/src/api.ts index a7d0649..bd74948 100644 --- a/front_end/src/api.ts +++ b/front_end/src/api.ts @@ -45,7 +45,7 @@ export const athleteService = { delete: (id: number | string) => api.delete(`/athlete/${id}`), // session-related endpoints exposed by AthleteResource - getSessionsForAthlete: (athleteId: number | string) => api.get(`/athletes/athlete/${athleteId}/session`), + getSessionsForAthlete: (athleteId: number | null) => api.get(`/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)}`), @@ -84,7 +84,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 | string) => api.get(`/coach/${coachId}/session`), + getSessionsForCoach: (coachId: number | null) => api.get(`/coach/${coachId}/session`), }; export const userService = { diff --git a/front_end/src/classes.tsx b/front_end/src/classes.tsx index 74ae159..b176e37 100644 --- a/front_end/src/classes.tsx +++ b/front_end/src/classes.tsx @@ -4,20 +4,21 @@ export type Groupe = "Entrainement" | "Competition" | "Loisir"| ""; export class Ligne{ - id!: number; + id: number|null = null; nom!: string; composition!: Athlete[] //les joueurs compososant la ligne tempsDeJeu!: number; // en minutes } export class User{ - id!: number; + id: number|null = null; keycloakId!: string; nom!: string; prenom!:string; email!: string; } + export class Admin extends User{ constructor(dto:AdminDTO); @@ -25,7 +26,7 @@ export class Admin extends User{ constructor(dto?:AdminDTO){ super(); - this.id = dto?.id ?? 0; + this.id = dto?.id ?? null; this.keycloakId = dto?.id_keycloak ?? ""; this.nom = dto?.name ?? ""; this.prenom = dto?.prenom ?? ""; @@ -113,7 +114,7 @@ export class Coach extends User{ } export class Session{ - id!: number; + id: number|null = null; name!: string; activitesID: number[] = []; activites: Activite[] = []; @@ -147,7 +148,7 @@ export class Session{ toDTO():SessionDTO{ const dto:SessionDTO = { - id: 0, + id: this.id, name: this.name, isRecurrent: this.isRecurrent, creneau: this.creneau.toISOString(), @@ -162,7 +163,7 @@ export class Session{ } export class Activite{ - id!: number; + id: number|null = null; nom!: string; session!: Session; theme!: string; @@ -184,7 +185,7 @@ export class Activite{ toDTO():ActiviteDTO{ const dto:ActiviteDTO = { - id: 0, + id: this.id, name: this.nom, duree: this.duree, dataActivite: [], diff --git a/front_end/src/classesDTO.tsx b/front_end/src/classesDTO.tsx index 5f7d466..cffde60 100644 --- a/front_end/src/classesDTO.tsx +++ b/front_end/src/classesDTO.tsx @@ -1,23 +1,23 @@ import { Groupe } from "./classes"; export type ActiviteDTO = { - id: number; + id: number|null; name: string; theme: string; duree: number; dataActivite: string[]; - sessionId: number; + sessionId: number|null; } export type AdminDTO = { - id: number; + id: number|null; id_keycloak: string; name: string; prenom: string; } export type AthleteDTO = { - id:number; + id:number|null; id_keycloak: string; name: string; prenom: string; @@ -28,7 +28,7 @@ export type AthleteDTO = { }; export type CoachDTO = { - id: number; + id: number|null; id_keycloak: string; name: string; prenom: string; @@ -36,14 +36,14 @@ export type CoachDTO = { }; export type SessionDTO = { - id: number; + id: number|null; name: string; isRecurrent: boolean; creneau: string; // LocalDateTime → ISO string duree: number; groupe: Groupe; - coachId: number; + coachId: number|null; athleteIds: number[]; activiteIds: number[]; }; diff --git a/front_end/src/components/ressourceList.tsx b/front_end/src/components/ressourceList.tsx index 27acfaa..a11730f 100644 --- a/front_end/src/components/ressourceList.tsx +++ b/front_end/src/components/ressourceList.tsx @@ -145,7 +145,7 @@ function LigneList({ lignes, tempsDeJeuParLigne }: LigneListProps) {
Temps de jeu total :{" "} - {tempsDeJeuParLigne.get(lignes.id) ?? 0} min + {/* {tempsDeJeuParLigne.get(lignes.id) ?? 0} min */}
))} diff --git a/front_end/src/requetes.tsx b/front_end/src/requetes.tsx index ff7a949..b5ff9c4 100644 --- a/front_end/src/requetes.tsx +++ b/front_end/src/requetes.tsx @@ -210,10 +210,14 @@ export async function getAllUserAPI(): Promise { } } -export async function getCoachByIdAPI(id:number): Promise { +export async function getCoachByIdAPI(id:number|null): Promise { try{ - const response = await coachService.getById(id); - return new Coach(response.data); + if(id!==null){ + const response = await coachService.getById(id); + return new Coach(response.data); + } + console.error("Error fetching coach by id : id null"); + return null; }catch (error) { console.error("Error fetching coach by id:", error); return null;