front correction id number|null
This commit is contained in:
@@ -44,11 +44,11 @@ public class SessionResource {
|
|||||||
@PreAuthorize("hasRole('coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
||||||
try {
|
try {
|
||||||
Session session = maptoEntity(dto);
|
if(sessionDAO.findById(dto.getId()).isPresent()) {
|
||||||
if(sessionDAO.findById(session.getId()).isPresent()) {
|
return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + dto.getId() + " already exists.");
|
||||||
return ResponseEntity.status(HttpStatus.OK).body("Session with ID " + session.getId() + " already exists.");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Session session = maptoEntity(dto);
|
||||||
Coach c = coachDAO.findById(dto.getCoachId()).orElse(null);
|
Coach c = coachDAO.findById(dto.getCoachId()).orElse(null);
|
||||||
session.setCoach(c);
|
session.setCoach(c);
|
||||||
sessionDAO.save(session);
|
sessionDAO.save(session);
|
||||||
@@ -161,7 +161,7 @@ public class SessionResource {
|
|||||||
|
|
||||||
private Session maptoEntity(SessionDTO dto) {
|
private Session maptoEntity(SessionDTO dto) {
|
||||||
Session session = new Session();
|
Session session = new Session();
|
||||||
System.out.println("ID "+ dto.getId());
|
System.out.println("ID "+ session.getId());
|
||||||
session.setName(dto.getName());
|
session.setName(dto.getName());
|
||||||
session.setIsRecurrent(dto.getIsRecurrent());
|
session.setIsRecurrent(dto.getIsRecurrent());
|
||||||
session.setCreneau(dto.getCreneau());
|
session.setCreneau(dto.getCreneau());
|
||||||
|
|||||||
@@ -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 | string) => api.get(`/athletes/athlete/${athleteId}/session`),
|
getSessionsForAthlete: (athleteId: number | null) => api.get(`/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)}`),
|
||||||
@@ -84,7 +84,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 | string) => api.get(`/coach/${coachId}/session`),
|
getSessionsForCoach: (coachId: number | null) => api.get(`/coach/${coachId}/session`),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const userService = {
|
export const userService = {
|
||||||
|
|||||||
@@ -4,20 +4,21 @@ export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
|||||||
|
|
||||||
|
|
||||||
export class Ligne{
|
export class Ligne{
|
||||||
id!: number;
|
id: number|null = null;
|
||||||
nom!: string;
|
nom!: string;
|
||||||
composition!: Athlete[] //les joueurs compososant la ligne
|
composition!: Athlete[] //les joueurs compososant la ligne
|
||||||
tempsDeJeu!: number; // en minutes
|
tempsDeJeu!: number; // en minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
export class User{
|
export class User{
|
||||||
id!: number;
|
id: number|null = null;
|
||||||
keycloakId!: string;
|
keycloakId!: string;
|
||||||
nom!: string;
|
nom!: string;
|
||||||
prenom!:string;
|
prenom!:string;
|
||||||
email!: string;
|
email!: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class Admin extends User{
|
export class Admin extends User{
|
||||||
|
|
||||||
constructor(dto:AdminDTO);
|
constructor(dto:AdminDTO);
|
||||||
@@ -25,7 +26,7 @@ export class Admin extends User{
|
|||||||
|
|
||||||
constructor(dto?:AdminDTO){
|
constructor(dto?:AdminDTO){
|
||||||
super();
|
super();
|
||||||
this.id = dto?.id ?? 0;
|
this.id = dto?.id ?? null;
|
||||||
this.keycloakId = dto?.id_keycloak ?? "";
|
this.keycloakId = dto?.id_keycloak ?? "";
|
||||||
this.nom = dto?.name ?? "";
|
this.nom = dto?.name ?? "";
|
||||||
this.prenom = dto?.prenom ?? "";
|
this.prenom = dto?.prenom ?? "";
|
||||||
@@ -113,7 +114,7 @@ export class Coach extends User{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Session{
|
export class Session{
|
||||||
id!: number;
|
id: number|null = null;
|
||||||
name!: string;
|
name!: string;
|
||||||
activitesID: number[] = [];
|
activitesID: number[] = [];
|
||||||
activites: Activite[] = [];
|
activites: Activite[] = [];
|
||||||
@@ -147,7 +148,7 @@ export class Session{
|
|||||||
|
|
||||||
toDTO():SessionDTO{
|
toDTO():SessionDTO{
|
||||||
const dto:SessionDTO = {
|
const dto:SessionDTO = {
|
||||||
id: 0,
|
id: this.id,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
isRecurrent: this.isRecurrent,
|
isRecurrent: this.isRecurrent,
|
||||||
creneau: this.creneau.toISOString(),
|
creneau: this.creneau.toISOString(),
|
||||||
@@ -162,7 +163,7 @@ export class Session{
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Activite{
|
export class Activite{
|
||||||
id!: number;
|
id: number|null = null;
|
||||||
nom!: string;
|
nom!: string;
|
||||||
session!: Session;
|
session!: Session;
|
||||||
theme!: string;
|
theme!: string;
|
||||||
@@ -184,7 +185,7 @@ export class Activite{
|
|||||||
|
|
||||||
toDTO():ActiviteDTO{
|
toDTO():ActiviteDTO{
|
||||||
const dto:ActiviteDTO = {
|
const dto:ActiviteDTO = {
|
||||||
id: 0,
|
id: this.id,
|
||||||
name: this.nom,
|
name: this.nom,
|
||||||
duree: this.duree,
|
duree: this.duree,
|
||||||
dataActivite: [],
|
dataActivite: [],
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
import { Groupe } from "./classes";
|
import { Groupe } from "./classes";
|
||||||
|
|
||||||
export type ActiviteDTO = {
|
export type ActiviteDTO = {
|
||||||
id: number;
|
id: number|null;
|
||||||
name: string;
|
name: string;
|
||||||
theme: string;
|
theme: string;
|
||||||
duree: number;
|
duree: number;
|
||||||
dataActivite: string[];
|
dataActivite: string[];
|
||||||
sessionId: number;
|
sessionId: number|null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AdminDTO = {
|
export type AdminDTO = {
|
||||||
id: number;
|
id: number|null;
|
||||||
id_keycloak: string;
|
id_keycloak: string;
|
||||||
name: string;
|
name: string;
|
||||||
prenom: string;
|
prenom: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AthleteDTO = {
|
export type AthleteDTO = {
|
||||||
id:number;
|
id:number|null;
|
||||||
id_keycloak: string;
|
id_keycloak: string;
|
||||||
name: string;
|
name: string;
|
||||||
prenom: string;
|
prenom: string;
|
||||||
@@ -28,7 +28,7 @@ export type AthleteDTO = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type CoachDTO = {
|
export type CoachDTO = {
|
||||||
id: number;
|
id: number|null;
|
||||||
id_keycloak: string;
|
id_keycloak: string;
|
||||||
name: string;
|
name: string;
|
||||||
prenom: string;
|
prenom: string;
|
||||||
@@ -36,14 +36,14 @@ export type CoachDTO = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type SessionDTO = {
|
export type SessionDTO = {
|
||||||
id: number;
|
id: number|null;
|
||||||
name: string;
|
name: string;
|
||||||
isRecurrent: boolean;
|
isRecurrent: boolean;
|
||||||
creneau: string; // LocalDateTime → ISO string
|
creneau: string; // LocalDateTime → ISO string
|
||||||
duree: number;
|
duree: number;
|
||||||
groupe: Groupe;
|
groupe: Groupe;
|
||||||
|
|
||||||
coachId: number;
|
coachId: number|null;
|
||||||
athleteIds: number[];
|
athleteIds: number[];
|
||||||
activiteIds: number[];
|
activiteIds: number[];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ function LigneList({ lignes, tempsDeJeuParLigne }: LigneListProps) {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong>Temps de jeu total :</strong>{" "}
|
<strong>Temps de jeu total :</strong>{" "}
|
||||||
{tempsDeJeuParLigne.get(lignes.id) ?? 0} min
|
{/* {tempsDeJeuParLigne.get(lignes.id) ?? 0} min */}
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -210,10 +210,14 @@ export async function getAllUserAPI(): Promise<User[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCoachByIdAPI(id:number): Promise<Coach|null> {
|
export async function getCoachByIdAPI(id:number|null): Promise<Coach|null> {
|
||||||
try{
|
try{
|
||||||
|
if(id!==null){
|
||||||
const response = await coachService.getById(id);
|
const response = await coachService.getById(id);
|
||||||
return new Coach(response.data);
|
return new Coach(response.data);
|
||||||
|
}
|
||||||
|
console.error("Error fetching coach by id : id null");
|
||||||
|
return null;
|
||||||
}catch (error) {
|
}catch (error) {
|
||||||
console.error("Error fetching coach by id:", error);
|
console.error("Error fetching coach by id:", error);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user