Frontend API interface
This commit is contained in:
@@ -3,13 +3,76 @@ import keycloak from "./keycloak";
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: "http://localhost:8081/api",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
if (keycloak?.token) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
config.headers.Authorization = `Bearer ${keycloak.token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
export const athleteService = {
|
||||
create: (data: any) => api.post("/athletes/create", data),
|
||||
getAll: () => api.get("/athletes/all"),
|
||||
getById: (id: number | string) => api.get(`/athletes/${id}`),
|
||||
update: (id: number | string, data: any) => api.put(`/athletes/${id}`, data),
|
||||
delete: (id: number | string) => api.delete(`/athletes/${id}`),
|
||||
|
||||
// session-related endpoints exposed by AthleteResource
|
||||
getSessionsForAthlete: (athleteId: number | string) => 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)}`),
|
||||
getSessionsBetweenDates: (athleteId: number | string, startDate: string, endDate: string) => api.get(`/athletes/${athleteId}/session/between/${encodeURIComponent(startDate)}/${encodeURIComponent(endDate)}`),
|
||||
};
|
||||
|
||||
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),
|
||||
getById: (id: number | string) => api.get(`/activite/${id}`),
|
||||
getAll: () => api.get(`/activite/all`),
|
||||
getByTheme: (theme: string) => api.get(`/activite/theme/${encodeURIComponent(theme)}`),
|
||||
};
|
||||
|
||||
export const sessionService = {
|
||||
// controller uses singular /session/* endpoints
|
||||
create: (data: any) => api.post(`/session/create`, data),
|
||||
getAll: () => api.get(`/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),
|
||||
|
||||
// plural variants used around the frontend (keep for compatibility)
|
||||
createPlural: (data: any) => api.post(`/sessions`, data),
|
||||
getAllPlural: () => api.get(`/sessions`),
|
||||
getActivities: (sessionId: number | string) => api.get(`/sessions/${sessionId}/activities`),
|
||||
addActivity: (sessionId: number | string, activity: any) => api.post(`/sessions/${sessionId}/activities`, activity),
|
||||
subscribe: (sessionId: number | string, userId: number | string) => api.post(`/sessions/${sessionId}/subscribe`, { userId }),
|
||||
unsubscribe: (sessionId: number | string, userId: number | string) => api.post(`/sessions/${sessionId}/unsubscribe`, { userId }),
|
||||
};
|
||||
|
||||
export const coachService = {
|
||||
// controller doesn't declare a class-level path consistently; support both common patterns
|
||||
create: (data: any) => api.post(`/coach/create`, data),
|
||||
getAll: () => api.get(`/coach/all`),
|
||||
getById: (id: number | string) => api.get(`/coach/${id}`),
|
||||
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
||||
delete: (id: number | string) => api.delete(`/coach/delete/${id}`),
|
||||
|
||||
// plural convenience
|
||||
createPlural: (data: any) => api.post(`/coaches`, data),
|
||||
getAllPlural: () => api.get(`/coaches`),
|
||||
};
|
||||
|
||||
export const userService = {
|
||||
getById: (id: number | string) => api.get(`/users/${id}`),
|
||||
getAll: () => api.get(`/users`),
|
||||
};
|
||||
|
||||
export default api;
|
||||
Reference in New Issue
Block a user