Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -2,7 +2,7 @@ import axios from "axios";
|
||||
|
||||
import keycloak from "./keycloak";
|
||||
import { get } from "http";
|
||||
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO";
|
||||
|
||||
|
||||
const api = axios.create({
|
||||
@@ -65,7 +65,7 @@ export const activiteService = {
|
||||
export const sessionService = {
|
||||
// controller uses singular /session/* endpoints
|
||||
create: (data: any) => api.post(`/session/create`, data),
|
||||
getAll: () => api.get(`/session/all`),
|
||||
getAll: () => api.get<SessionDTO[]>(`/session/all`),
|
||||
getById: (id: number | string) => api.get(`/session/${id}`),
|
||||
delete: (id: number | string) => api.delete(`/session/delete/${id}`),
|
||||
update: (id: number | string, data: any) => api.put(`/session/update/${id}`, data),
|
||||
|
||||
@@ -19,10 +19,10 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
const [value,setValue] = useState<keyWord>("sessions");
|
||||
|
||||
const[allAthletes,setAllAthletes] = useState<Athlete[]>([]);
|
||||
const[allActivites,setAllActivites] = useState<Activite[]>([]);
|
||||
const[allCoachs,setAllCoachs] = useState<Coach[]>([]);
|
||||
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
||||
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
||||
const[allActivites,setAllActivites] = useState<Activite[]>([]);
|
||||
|
||||
|
||||
async function updateAthletes() {
|
||||
@@ -34,6 +34,8 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
|
||||
async function updateSessions() {
|
||||
const sessions:Session[] = await getAllSessionsAPI();
|
||||
setAllSessions(sessions);
|
||||
console.log("GET ALL SESSION ");
|
||||
}
|
||||
|
||||
async function updateLignes() {
|
||||
@@ -86,7 +88,7 @@ import { useKeycloak } from "@react-keycloak/web";
|
||||
))
|
||||
)}
|
||||
{value==="activites" && (
|
||||
allActivites.map((activite) => (
|
||||
allActivites.map(activite => (
|
||||
<ObjectActivite activite={activite}/>
|
||||
))
|
||||
)}
|
||||
|
||||
@@ -199,6 +199,16 @@ export async function getAllUserAPI(): Promise<User[]> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCoachByIdAPI(id:number): Promise<Coach|null> {
|
||||
try{
|
||||
const response = await coachService.getById(id);
|
||||
return new Coach(response.data);
|
||||
}catch (error) {
|
||||
console.error("Error fetching coach by id:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//SESSION
|
||||
export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
try {
|
||||
@@ -218,7 +228,19 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
export async function getAllSessionsAPI():Promise<Session[]>{
|
||||
try {
|
||||
const response = await sessionService.getAll();
|
||||
return response.data;
|
||||
const sessions = await Promise.all(
|
||||
response.data.map(async sessionDTO => {
|
||||
const session = new Session(sessionDTO);
|
||||
const coach = await getCoachByIdAPI(sessionDTO.coachId);
|
||||
|
||||
if (coach != null) {
|
||||
session.coach = coach;
|
||||
}
|
||||
return session;
|
||||
})
|
||||
);
|
||||
|
||||
return sessions;
|
||||
} catch (error) {
|
||||
console.error("Error fetching sessions:", error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user