getSessions
This commit is contained in:
@@ -2,7 +2,7 @@ import axios from "axios";
|
|||||||
|
|
||||||
import keycloak from "./keycloak";
|
import keycloak from "./keycloak";
|
||||||
import { get } from "http";
|
import { get } from "http";
|
||||||
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO";
|
||||||
|
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
@@ -65,7 +65,7 @@ export const activiteService = {
|
|||||||
export const sessionService = {
|
export const sessionService = {
|
||||||
// controller uses singular /session/* endpoints
|
// controller uses singular /session/* endpoints
|
||||||
create: (data: any) => api.post(`/session/create`, data),
|
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}`),
|
getById: (id: number | string) => api.get(`/session/${id}`),
|
||||||
delete: (id: number | string) => api.delete(`/session/delete/${id}`),
|
delete: (id: number | string) => api.delete(`/session/delete/${id}`),
|
||||||
update: (id: number | string, data: any) => api.put(`/session/update/${id}`, data),
|
update: (id: number | string, data: any) => api.put(`/session/update/${id}`, data),
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { useKeycloak } from "@react-keycloak/web";
|
|||||||
const [value,setValue] = useState<keyWord>("sessions");
|
const [value,setValue] = useState<keyWord>("sessions");
|
||||||
|
|
||||||
const[allAthletes,setAllAthletes] = useState<Athlete[]>([]);
|
const[allAthletes,setAllAthletes] = useState<Athlete[]>([]);
|
||||||
|
const[allActivites,setAllActivites] = useState<Activite[]>([]);
|
||||||
const[allCoachs,setAllCoachs] = useState<Coach[]>([]);
|
const[allCoachs,setAllCoachs] = useState<Coach[]>([]);
|
||||||
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
const[allSessions,setAllSessions] = useState<Session[]>([]);
|
||||||
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
const[allLignes,setAllLignes] = useState<Ligne[]>([]);
|
||||||
@@ -33,6 +34,8 @@ import { useKeycloak } from "@react-keycloak/web";
|
|||||||
|
|
||||||
async function updateSessions() {
|
async function updateSessions() {
|
||||||
const sessions:Session[] = await getAllSessionsAPI();
|
const sessions:Session[] = await getAllSessionsAPI();
|
||||||
|
setAllSessions(sessions);
|
||||||
|
console.log("GET ALL SESSION ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateLignes() {
|
async function updateLignes() {
|
||||||
@@ -85,7 +88,7 @@ import { useKeycloak } from "@react-keycloak/web";
|
|||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
{value==="activites" && (
|
{value==="activites" && (
|
||||||
allActivites.map((activite) => (
|
allActivites.map(activite => (
|
||||||
<ObjectActivite activite={activite}/>
|
<ObjectActivite activite={activite}/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -223,7 +223,12 @@ export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
|||||||
export async function getAllSessionsAPI():Promise<Session[]>{
|
export async function getAllSessionsAPI():Promise<Session[]>{
|
||||||
try {
|
try {
|
||||||
const response = await sessionService.getAll();
|
const response = await sessionService.getAll();
|
||||||
return response.data;
|
const sessions:Session[] = [];
|
||||||
|
response.data.forEach(sessionDTO => {
|
||||||
|
sessions.push(new Session(sessionDTO));
|
||||||
|
|
||||||
|
});
|
||||||
|
return sessions;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching sessions:", error);
|
console.error("Error fetching sessions:", error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user