merge
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import api from "./api";
|
||||
import { Activite, Athlete, Coach, Session, User } from "./classes";
|
||||
import { useKeycloak } from '@react-keycloak/web'
|
||||
|
||||
@@ -16,50 +17,95 @@ const useAuthHeader = () => {
|
||||
/*
|
||||
retourne l'utilisateur lié à l'identifiant keyloack
|
||||
*/
|
||||
export async function getUser(id:number): Promise<boolean>{
|
||||
//keycloak.id;
|
||||
return true;
|
||||
export async function getUser(id:number): Promise<User|null>{
|
||||
try {
|
||||
const response = await api.get<User>(`/users/${id}`);
|
||||
return response.data;
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error fetching user:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
retourne toutes les Session dont l'user est inscrit
|
||||
*/
|
||||
export async function updateSessionsOfUser(user:Coach|Athlete, min: Date|null, max: Date|null){
|
||||
//TODO
|
||||
export async function updateSessionsOfUserAPI(user:Coach|Athlete, min: Date|null, max: Date|null){
|
||||
try {
|
||||
const response = await api.get<Session[]>(`/users/${user.id}/sessions`, {
|
||||
params: {
|
||||
minDate: min ? min.toISOString() : undefined,
|
||||
maxDate: max ? max.toISOString() : undefined
|
||||
}
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching sessions for user:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateActivitiesOfSession(session:Session){
|
||||
//TODO
|
||||
export async function updateActivitiesOfSessionAPI(session:Session){
|
||||
try {
|
||||
const response = await api.get<Activite[]>(`/sessions/${session.id}/activities`);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching activities for session:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function subscribeSession(user:User, session:Session):Promise<boolean>{
|
||||
return true;
|
||||
export async function subscribeSessionAPI(user:User, session:Session):Promise<boolean>{
|
||||
try {
|
||||
await api.post(`/sessions/${session.id}/subscribe`, { userId: user.id });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error subscribing to session:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function unsubscribeSession(user:User, session:Session):Promise<boolean>{
|
||||
return true;
|
||||
export async function unsubscribeSessionAPI(user:User, session:Session):Promise<boolean>{
|
||||
try {
|
||||
await api.post(`/sessions/${session.id}/unsubscribe`, { userId: user.id });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error unsubscribing from session:", error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ADMIN :
|
||||
|
||||
export async function updateAllSession(min: Date, max: Date){
|
||||
export async function updateAllSessionAPI(min: Date, max: Date){
|
||||
//TODO
|
||||
}
|
||||
|
||||
export async function updateAllUser(){
|
||||
export async function updateAllUserAPI(){
|
||||
|
||||
}
|
||||
|
||||
// POST /////////////////////////////////////////////////////////
|
||||
|
||||
// COACH ADMIN
|
||||
export async function postSession(session: Session){
|
||||
|
||||
export async function createSessionAPI(newSession: Session): Promise<Session> {
|
||||
try {
|
||||
const response = await api.post<Session>("/sessions", newSession);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error creating session:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function postActivity(session: Session, activity: Activite){
|
||||
//post nouvelle activitée
|
||||
|
||||
//associer la nouvelle activité à la session
|
||||
export async function postActivityAPI(session: Session, activity: Activite){
|
||||
try {
|
||||
const response = await api.post<Activite>(`/sessions/${session.id}/activities`, activity);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error creating activity:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function postUser(user: User):Promise<boolean>{
|
||||
@@ -69,11 +115,30 @@ export async function postUser(user: User):Promise<boolean>{
|
||||
// SET /////////////////////////////////////////////////////////
|
||||
|
||||
//ADMIN
|
||||
export async function setUserName(user: User, name: string){
|
||||
export async function setUserNameAPI(user: User, name: string){
|
||||
|
||||
}
|
||||
|
||||
//COACH
|
||||
export async function setSessionCreneau(session: Session, date:Date){
|
||||
export async function setSessionCreneauAPI(session: Session, date:Date){
|
||||
|
||||
}
|
||||
|
||||
export async function getSessionsAPI(): Promise<Session[]> {
|
||||
try {
|
||||
const response = await api.get<Session[]>("/sessions");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching sessions:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
export async function getUsersAPI(): Promise<User[]> {
|
||||
try {
|
||||
const response = await api.get<User[]>("/users");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user