change endpoints
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
package hackathon.FrisbYEE.rest;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class UserSyncResource {
|
||||
@Autowired
|
||||
private AthleteDAO athleteDAO;
|
||||
|
||||
@PostMapping("/sync")
|
||||
@Transactional
|
||||
public ResponseEntity<Void> sync() {
|
||||
Jwt jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
String keycloakId = jwt.getSubject();
|
||||
String firstName = jwt.getClaimAsString("given_name");
|
||||
String lastName = jwt.getClaimAsString("family_name");
|
||||
if (!athleteDAO.existsByKeycloakId(keycloakId)) {
|
||||
Athlete athlete = new Athlete();
|
||||
athlete.setKeycloakId(keycloakId);
|
||||
athlete.setName(lastName);
|
||||
athlete.setPrenom(firstName);
|
||||
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
||||
athleteDAO.save(athlete);
|
||||
}
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
@@ -70,9 +70,6 @@ export const sessionService = {
|
||||
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 }),
|
||||
@@ -87,9 +84,6 @@ export const coachService = {
|
||||
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
||||
delete: (id: number | string) => api.delete(`/coach/delete/${id}`),
|
||||
getSessionsForCoach: (coachId: number | string) => api.get(`/coach/${coachId}/session`),
|
||||
// plural convenience
|
||||
createPlural: (data: any) => api.post(`/coaches`, data),
|
||||
getAllPlural: () => api.get(`/coaches`),
|
||||
};
|
||||
|
||||
export const userService = {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react"
|
||||
import { Athlete, Coach, Session} from "../classes"
|
||||
import { useLocalData } from "../context/useLocalData"
|
||||
import './style/edt.css';
|
||||
import {updateSessionsOfUserAPI } from "../requetes";
|
||||
import {getSessionsOfUserAPI } from "../requetes";
|
||||
import EdtSession from "./edt_session";
|
||||
import {delay} from "../requetes";
|
||||
import Loading from "./loading";
|
||||
@@ -34,9 +34,6 @@ export const EDT =() =>{
|
||||
const week_days:String[] = ["Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"];
|
||||
const week_days_nums:number[] = [1,2,3,4,5,6,0];
|
||||
|
||||
|
||||
|
||||
|
||||
function loadSessions(date:Date){
|
||||
var maxDate = getNextDay(date,6)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import api, { activiteService, athleteService, coachService, sessionService } fr
|
||||
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
||||
import Keycloak from 'keycloak-js'
|
||||
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||
import { useLocalData } from "./context/useLocalData";
|
||||
|
||||
//debug:
|
||||
export function delay(ms: number): Promise<void> {
|
||||
@@ -45,24 +46,6 @@ export async function getUser(keycloak:Keycloak): Promise<User|null>{
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
retourne toutes les Session dont l'user est inscrit
|
||||
*/
|
||||
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 updateActivitiesOfSessionAPI(session:Session){
|
||||
try {
|
||||
const response = await api.get<Activite[]>(`/sessions/${session.id}/activities`);
|
||||
@@ -95,10 +78,6 @@ export async function unsubscribeSessionAPI(user:User, session:Session):Promise<
|
||||
|
||||
// ADMIN :
|
||||
|
||||
export async function updateAllSessionAPI(min: Date, max: Date){
|
||||
//TODO
|
||||
}
|
||||
|
||||
export async function updateAllUserAPI(){
|
||||
|
||||
}
|
||||
@@ -193,26 +172,27 @@ export async function setSessionCreneauAPI(session: Session, date:Date){
|
||||
|
||||
}
|
||||
|
||||
export async function getSessionsAPI(): Promise<Session[]> {
|
||||
//GET /////////////////////////////////////////////////////////
|
||||
|
||||
//SESSION
|
||||
|
||||
export async function getSessionsOfUserAPI(user:Coach|Athlete){
|
||||
try {
|
||||
const response = await api.get<Session[]>("/session");
|
||||
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[]>("/coach/all");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
if (user instanceof Coach) {
|
||||
const response = await coachService.getSessionsForCoach(user.id); //TODO
|
||||
return response.data;
|
||||
}else if (user instanceof Athlete) {
|
||||
const response = await athleteService.getSessionsForAthlete(user.id); //TODO
|
||||
return response.data;
|
||||
}
|
||||
}catch (error) {
|
||||
console.error("Error fetching sessions for user:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCoachsAPI(): Promise<Coach[]> {
|
||||
//COACH
|
||||
export async function getAllCoach(): Promise<Coach[]> {
|
||||
try {
|
||||
const response = await api.get<Coach[]>("/coach/all");
|
||||
console.log(response);
|
||||
@@ -221,4 +201,16 @@ export async function getCoachsAPI(): Promise<Coach[]> {
|
||||
console.error("Error fetching coachs:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//ATHLETE
|
||||
export async function getAllAthlete(): Promise<Athlete[]> {
|
||||
try {
|
||||
const response = await athleteService.getAll();
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user