Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@@ -9,18 +9,15 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|||||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||||
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/users")
|
@RequestMapping("/users")
|
||||||
@CrossOrigin(origins = "http://localhost:3000")
|
@CrossOrigin(origins = "http://localhost:3000")
|
||||||
public class UserSyncResource {
|
public class UserSyncResource {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AthleteDAO athleteDAO;
|
private AthleteDAO athleteDAO;
|
||||||
|
|
||||||
@@ -28,13 +25,10 @@ public class UserSyncResource {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public ResponseEntity<Void> sync() {
|
public ResponseEntity<Void> sync() {
|
||||||
Jwt jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
Jwt jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
|
||||||
String keycloakId = jwt.getSubject();
|
String keycloakId = jwt.getSubject();
|
||||||
String firstName = jwt.getClaimAsString("given_name");
|
String firstName = jwt.getClaimAsString("given_name");
|
||||||
String lastName = jwt.getClaimAsString("family_name");
|
String lastName = jwt.getClaimAsString("family_name");
|
||||||
|
|
||||||
if (!athleteDAO.existsByKeycloakId(keycloakId)) {
|
if (!athleteDAO.existsByKeycloakId(keycloakId)) {
|
||||||
System.out.println("New user detected from Keycloak. Syncing: " + firstName + " " + lastName);
|
|
||||||
Athlete athlete = new Athlete();
|
Athlete athlete = new Athlete();
|
||||||
athlete.setKeycloakId(keycloakId);
|
athlete.setKeycloakId(keycloakId);
|
||||||
athlete.setName(lastName);
|
athlete.setName(lastName);
|
||||||
@@ -42,7 +36,6 @@ public class UserSyncResource {
|
|||||||
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
||||||
athleteDAO.save(athlete);
|
athleteDAO.save(athlete);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,21 +11,13 @@ import EdtCoach from './components/edt_coach'
|
|||||||
import { Coach } from "./classes";
|
import { Coach } from "./classes";
|
||||||
import RessourcePanel from './components/ressourcePanel';
|
import RessourcePanel from './components/ressourcePanel';
|
||||||
import TestAPI from './components/test_api';
|
import TestAPI from './components/test_api';
|
||||||
import EdtAthlete from './components/edt_athlete';
|
|
||||||
// Test
|
|
||||||
const testCoach = new Coach();
|
|
||||||
testCoach.id = 1;
|
|
||||||
testCoach.nom = "Coach Test";
|
|
||||||
|
|
||||||
const keycloakInitOptions = {
|
const keycloakInitOptions = {
|
||||||
onLoad: 'login-required',
|
onLoad: 'login-required',
|
||||||
checkLoginIframe: false
|
checkLoginIframe: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactKeycloakProvider authClient={keycloak} /*initOptions={keycloakInitOptions}*/>
|
<ReactKeycloakProvider authClient={keycloak} /*initOptions={keycloakInitOptions}*/>
|
||||||
<LocalDataProvider>
|
<LocalDataProvider>
|
||||||
@@ -36,7 +28,6 @@ function App() {
|
|||||||
<RessourcePanel/>
|
<RessourcePanel/>
|
||||||
<EDT/>
|
<EDT/>
|
||||||
<CreateSession/>
|
<CreateSession/>
|
||||||
<EdtAthlete/>
|
|
||||||
<TestAPI/>
|
<TestAPI/>
|
||||||
</div>
|
</div>
|
||||||
</LocalDataProvider>
|
</LocalDataProvider>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ api.interceptors.request.use((config) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Helpers to set/clear the Authorization header programmatically (call after Keycloak login)
|
// Helpers to set/clear the Authorization header programmatically (call after Keycloak login)
|
||||||
export function setAuthToken(token: string | null) {
|
export function setAuthToken(token: string | null | undefined) {
|
||||||
if (token) {
|
if (token) {
|
||||||
api.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
api.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,15 +1,7 @@
|
|||||||
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
import { ActiviteDTO, AdminDTO, AthleteDTO, CoachDTO, SessionDTO } from "./classesDTO";
|
||||||
export type Role = "admin" | "athlete" | "coach";
|
|
||||||
|
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
||||||
|
|
||||||
export class User{
|
|
||||||
id!: number;
|
|
||||||
keycloakId!: String;
|
|
||||||
nom!: string;
|
|
||||||
prenom!:string;
|
|
||||||
sessions: Session[] = []; //nb: Admin liaison non symétrique /!\
|
|
||||||
email!: string;
|
|
||||||
role!: Role;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Ligne{
|
export class Ligne{
|
||||||
id!: number;
|
id!: number;
|
||||||
@@ -18,32 +10,103 @@ export class Ligne{
|
|||||||
tempsDeJeu!: number; // en minutes
|
tempsDeJeu!: number; // en minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class User{
|
||||||
|
id!: number;
|
||||||
|
keycloakId!: String;
|
||||||
|
nom!: string;
|
||||||
|
prenom!:string;
|
||||||
|
email!: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class Admin extends User{
|
export class Admin extends User{
|
||||||
role!: Role;
|
|
||||||
|
constructor(dto:AdminDTO);
|
||||||
|
constructor();
|
||||||
|
|
||||||
|
constructor(dto?:AdminDTO){
|
||||||
|
super();
|
||||||
|
this.id = dto?.id ?? 0;
|
||||||
|
this.keycloakId = dto?.id_keycloak ?? "";
|
||||||
|
this.nom = dto?.name ?? "";
|
||||||
|
this.prenom = dto?.prenom ?? "";
|
||||||
|
this.email = ""; //TODO
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Athlete extends User{
|
export class Athlete extends User{
|
||||||
nom!: string;
|
groupes!: Groupe[];
|
||||||
groupe!: Groupe;
|
sessionsID!: number[];
|
||||||
role!: Role;
|
sessions: Session[] = [];
|
||||||
|
|
||||||
|
constructor(dto:AthleteDTO);
|
||||||
|
constructor();
|
||||||
|
|
||||||
|
constructor(dto?:AthleteDTO){
|
||||||
|
super();
|
||||||
|
this.id = dto?.id ?? 0;
|
||||||
|
this.keycloakId = dto?.id_keycloak ?? "";
|
||||||
|
this.nom = dto?.name ?? "";
|
||||||
|
this.prenom = dto?.prenom ?? "" ;
|
||||||
|
this.email = ""; //TODO
|
||||||
|
this.groupes = dto?.groupes ?? [];
|
||||||
|
this.sessionsID = dto?.sessionIds ?? [];
|
||||||
|
this.sessions = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Coach extends User{
|
export class Coach extends User{
|
||||||
nom!: string;
|
nom!: string;
|
||||||
role!: Role;
|
sessionsID!: number[];
|
||||||
|
sessions: Session[] = [];
|
||||||
|
|
||||||
|
constructor(dto:CoachDTO);
|
||||||
|
constructor();
|
||||||
|
|
||||||
|
constructor(dto?:CoachDTO){
|
||||||
|
super();
|
||||||
|
this.id = dto?.id ?? 0;
|
||||||
|
this.keycloakId = dto?.id_keycloak ?? "";
|
||||||
|
this.nom = dto?.name ?? "";
|
||||||
|
this.prenom = dto?.prenom ?? "";
|
||||||
|
this.email = ""; //TODO
|
||||||
|
this.sessionsID = dto?.sessionIds ?? [];
|
||||||
|
this.sessions = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Session{
|
export class Session{
|
||||||
id!: number;
|
id!: number;
|
||||||
name!: string;
|
name!: string;
|
||||||
|
activitesID: number[] = [];
|
||||||
activites: Activite[] = [];
|
activites: Activite[] = [];
|
||||||
isRecurrent! : Boolean;
|
isRecurrent! : Boolean;
|
||||||
creneau!: Date;
|
creneau!: Date;
|
||||||
coach!: Coach;
|
coach!: Coach;
|
||||||
|
athletesID!: number[]
|
||||||
athletes!: Athlete[]
|
athletes!: Athlete[]
|
||||||
duree! : number;
|
duree! : number;
|
||||||
groupe! : Groupe;
|
groupe! : Groupe;
|
||||||
ligne! : Ligne[];
|
ligne! : Ligne[];
|
||||||
|
|
||||||
|
constructor(dto:SessionDTO);
|
||||||
|
constructor();
|
||||||
|
|
||||||
|
constructor(dto?:SessionDTO){
|
||||||
|
this.id = dto?.id?? 0;
|
||||||
|
this.name = dto?.name?? "";
|
||||||
|
this.activitesID = dto?.activiteIds?? [];
|
||||||
|
this.activites = [];
|
||||||
|
this.isRecurrent = dto?.isRecurrent?? false;
|
||||||
|
this.creneau = dto? new Date(dto.creneau) : new Date();
|
||||||
|
//this.coach = new Coach(); //dto.coachId; //TODO
|
||||||
|
this.athletesID = dto?.athleteIds ?? [];
|
||||||
|
this.athletes = [];
|
||||||
|
this.duree = dto?.duree ?? 0;
|
||||||
|
this.groupe = dto?.groupe ?? "";
|
||||||
|
this.ligne = []; //TODO
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Activite{
|
export class Activite{
|
||||||
@@ -54,10 +117,23 @@ export class Activite{
|
|||||||
data!: Map<string,string>;
|
data!: Map<string,string>;
|
||||||
duree!: number;
|
duree!: number;
|
||||||
|
|
||||||
}
|
constructor(dto:ActiviteDTO);
|
||||||
|
constructor();
|
||||||
|
|
||||||
|
constructor(dto?:ActiviteDTO){
|
||||||
|
this.id = dto?.id ?? 0;
|
||||||
|
this.nom = dto?.name ?? "";
|
||||||
|
//this.session = dto.sessionId; //TODO
|
||||||
|
this.theme = dto?.theme ?? "";
|
||||||
|
//this.data = //TODO
|
||||||
|
this.duree = dto?.duree ?? 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
export function getUserTest():User{
|
export function getUserTest():User{
|
||||||
const user = new User();
|
const user = new Athlete();
|
||||||
const s1 = new Session();
|
const s1 = new Session();
|
||||||
const s2 = new Session();
|
const s2 = new Session();
|
||||||
const s3 = new Session();
|
const s3 = new Session();
|
||||||
@@ -65,17 +141,17 @@ export function getUserTest():User{
|
|||||||
athlete1.id = 1;
|
athlete1.id = 1;
|
||||||
athlete1.nom = "Alice Dupont";
|
athlete1.nom = "Alice Dupont";
|
||||||
athlete1.email = "alice@nootnoot.yee";
|
athlete1.email = "alice@nootnoot.yee";
|
||||||
athlete1.groupe = "Entrainement";
|
athlete1.groupes = ["Entrainement"];
|
||||||
|
|
||||||
const athlete2 = new Athlete();
|
const athlete2 = new Athlete();
|
||||||
athlete2.id = 2;
|
athlete2.id = 2;
|
||||||
athlete2.nom = "Bob Martin";
|
athlete2.nom = "Bob Martin";
|
||||||
athlete2.groupe = "Competition";
|
athlete2.groupes = ["Competition"];
|
||||||
|
|
||||||
const athlete3 = new Athlete();
|
const athlete3 = new Athlete();
|
||||||
athlete3.id = 3;
|
athlete3.id = 3;
|
||||||
athlete3.nom = "Clara Lopez";
|
athlete3.nom = "Clara Lopez";
|
||||||
athlete3.groupe = "Loisir";
|
athlete3.groupes = ["Loisir"];
|
||||||
|
|
||||||
const ligne1 = new Ligne();
|
const ligne1 = new Ligne();
|
||||||
ligne1.id = 1;
|
ligne1.id = 1;
|
||||||
@@ -99,7 +175,6 @@ export function getUserTest():User{
|
|||||||
|
|
||||||
user.id = 0;
|
user.id = 0;
|
||||||
user.nom = "Emilien-Yee NootNoot";
|
user.nom = "Emilien-Yee NootNoot";
|
||||||
user.role = "coach"
|
|
||||||
user.email = "emilien@nootnoot.yee";
|
user.email = "emilien@nootnoot.yee";
|
||||||
s1.creneau = new Date();
|
s1.creneau = new Date();
|
||||||
s1.id = 1;
|
s1.id = 1;
|
||||||
@@ -187,9 +262,7 @@ export function getUserTest():User{
|
|||||||
user.sessions.push(s2);
|
user.sessions.push(s2);
|
||||||
user.sessions.push(s3);
|
user.sessions.push(s3);
|
||||||
|
|
||||||
athlete1.role = "athlete";
|
|
||||||
athlete2.role = "athlete";
|
|
||||||
athlete3.role = "athlete";
|
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
50
front_end/src/classesDTO.tsx
Normal file
50
front_end/src/classesDTO.tsx
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { Groupe } from "./classes";
|
||||||
|
|
||||||
|
export type ActiviteDTO = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
theme: string;
|
||||||
|
duree: number;
|
||||||
|
dataActivite: string[];
|
||||||
|
sessionId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AdminDTO = {
|
||||||
|
id: number;
|
||||||
|
id_keycloak: string;
|
||||||
|
name: string;
|
||||||
|
prenom: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AthleteDTO = {
|
||||||
|
id:number;
|
||||||
|
id_keycloak: string;
|
||||||
|
name: string;
|
||||||
|
prenom: string;
|
||||||
|
categorie: string;
|
||||||
|
niveau: string;
|
||||||
|
groupes: Groupe[];
|
||||||
|
sessionIds: number[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CoachDTO = {
|
||||||
|
id: number;
|
||||||
|
id_keycloak: string;
|
||||||
|
name: string;
|
||||||
|
prenom: string;
|
||||||
|
sessionIds: number[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SessionDTO = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
isRecurrent: boolean;
|
||||||
|
creneau: string; // LocalDateTime → ISO string
|
||||||
|
duree: number;
|
||||||
|
groupe: Groupe;
|
||||||
|
|
||||||
|
coachId: number;
|
||||||
|
athleteIds: number[];
|
||||||
|
activiteIds: number[];
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
|
|
||||||
export const EdtAthlete = () => {
|
|
||||||
const [formData, setFormData] = useState({
|
|
||||||
name: '',
|
|
||||||
prenom: '',
|
|
||||||
id_keycloak: '',
|
|
||||||
categorie: '',
|
|
||||||
niveau: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
try {
|
|
||||||
const response = await fetch("http://localhost:8081/api/athlete/create", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(formData),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.ok) {
|
|
||||||
alert("Athlete created successfully in PostgreSQL!");
|
|
||||||
setFormData({ name: '', prenom: '', id_keycloak: '', categorie: '', niveau: '' });
|
|
||||||
} else {
|
|
||||||
alert("Failed to create athlete. Status: " + response.status);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error creating athlete:", error);
|
|
||||||
alert("Error: Check console");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div style={{ padding: '20px', border: '1px solid #ccc', margin: '10px' }}>
|
|
||||||
<h3>Test Create Athlete (PostgreSQL)</h3>
|
|
||||||
<form onSubmit={handleSubmit}>
|
|
||||||
<div>
|
|
||||||
<label>Nom: </label>
|
|
||||||
<input type="text" value={formData.name} onChange={(e) => setFormData({...formData, name: e.target.value})} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Prénom: </label>
|
|
||||||
<input type="text" value={formData.prenom} onChange={(e) => setFormData({...formData, prenom: e.target.value})} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Keycloak ID: </label>
|
|
||||||
<input type="text" value={formData.id_keycloak} onChange={(e) => setFormData({...formData, id_keycloak: e.target.value})} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Catégorie: </label>
|
|
||||||
<input type="text" value={formData.categorie} onChange={(e) => setFormData({...formData, categorie: e.target.value})} />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Niveau: </label>
|
|
||||||
<input type="text" value={formData.niveau} onChange={(e) => setFormData({...formData, niveau: e.target.value})} />
|
|
||||||
</div>
|
|
||||||
<button type="submit" style={{ marginTop: '10px' }}>Créer l'athlète</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EdtAthlete;
|
|
||||||
@@ -1,45 +1,53 @@
|
|||||||
import { useKeycloak } from '@react-keycloak/web'
|
import { useKeycloak } from '@react-keycloak/web'
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { getUserTest, User } from '../classes';
|
import { Athlete, User } from '../classes';
|
||||||
import { useLocalData } from '../context/useLocalData';
|
import { useLocalData } from '../context/useLocalData';
|
||||||
import { setAuthToken, clearAuthToken } from '../api';
|
import { postAthlete } from '../requetes';
|
||||||
|
import { clearAuthToken, setAuthToken } from '../api';
|
||||||
|
|
||||||
export const Login =() =>{
|
export const Login =() =>{
|
||||||
const {user,setUser} = useLocalData()
|
const {user,setUser} = useLocalData()
|
||||||
const { keycloak } = useKeycloak();
|
const { keycloak } = useKeycloak();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const syncAndLoadUser = async () => {
|
const syncAndLoadUser = async () => {
|
||||||
if (keycloak.authenticated && keycloak.token) {
|
const newAthlete:Athlete = new Athlete()
|
||||||
const tokenParsed = keycloak.tokenParsed;
|
|
||||||
// set axios default auth header for API calls
|
|
||||||
setAuthToken(keycloak.token);
|
|
||||||
setUser({
|
|
||||||
id: 0,
|
|
||||||
keycloakId: tokenParsed!.sub!,
|
|
||||||
email: tokenParsed?.email || "",
|
|
||||||
nom: tokenParsed?.family_name || "",
|
|
||||||
prenom: tokenParsed?.given_name || "",
|
|
||||||
role: "athlete",
|
|
||||||
sessions: []
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
const response = await fetch("http://localhost:8081/api/users/sync", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Authorization": `Bearer ${keycloak.token}`,
|
|
||||||
"Content-Type": "application/json"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log("Sync status:", response.status);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Sync fetch failed:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
syncAndLoadUser();
|
const athlete:Athlete = await postAthlete(newAthlete)
|
||||||
}, [keycloak.authenticated, keycloak.token, setUser]);
|
|
||||||
|
setAuthToken(keycloak.token);
|
||||||
|
setUser(athlete);
|
||||||
|
/*postAthlete
|
||||||
|
if (keycloak.authenticated && keycloak.token) {
|
||||||
|
const tokenParsed = keycloak.tokenParsed;
|
||||||
|
setUser(
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
keycloakId: tokenParsed!.sub!,
|
||||||
|
email: tokenParsed?.email || "",
|
||||||
|
nom: tokenParsed?.family_name || "",
|
||||||
|
prenom: tokenParsed?.given_name || "",
|
||||||
|
sessions: []
|
||||||
|
}
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const response = await fetch("http://localhost:8081/api/users/sync", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${keycloak.token}`,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log("Sync status:", response.status);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Sync fetch failed:", error);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
};
|
||||||
|
|
||||||
|
syncAndLoadUser();
|
||||||
|
}, [keycloak.authenticated, keycloak.token, setUser]);
|
||||||
|
|
||||||
|
|
||||||
function handleLogin(): void {
|
function handleLogin(): void {
|
||||||
@@ -65,9 +73,6 @@ export const Login =() =>{
|
|||||||
<div>
|
<div>
|
||||||
User nom : { user.nom}
|
User nom : { user.nom}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
User role : { user.role}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,20 +101,19 @@ function ObjectUser({admin=null,athlete=null,coach=null}:Props){
|
|||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
<div className="object" onClick={() => handleOpen()}>
|
<div className="object" onClick={() => handleOpen()}>
|
||||||
<div>{user2.nom} ({user2.role})</div>
|
<div>{user2.nom}</div>
|
||||||
|
|
||||||
{/* <div>{user2.role}</div> */}
|
{/* <div>{user2.role}</div> */}
|
||||||
</div>
|
</div>
|
||||||
{open &&
|
{open &&
|
||||||
<Modal isOpen={open} onClose={() => setOpen(false)}>
|
<Modal isOpen={open} onClose={() => setOpen(false)}>
|
||||||
<div className="object_modal">
|
<div className="object_modal">
|
||||||
<div>{user2.nom} ({user2.role})</div>
|
<div>{user2.nom}</div>
|
||||||
<div>{user2.email}</div>
|
<div>{user2.email}</div>
|
||||||
<div className='list_object'>
|
<div className='list_object'>
|
||||||
<div>Sessions :</div>
|
<div>Sessions :</div>
|
||||||
{user.sessions.map((session,index)=>(
|
{/* TODO */}
|
||||||
<ObjectSession session={session}/>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
{athlete !== null && (
|
{athlete !== null && (
|
||||||
<div className="stats-container">
|
<div className="stats-container">
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ function AthleteList({ athletes, sessions }: AthleteListProps) {
|
|||||||
return (
|
return (
|
||||||
<li key={a.id}>
|
<li key={a.id}>
|
||||||
<div><strong>Nom:</strong> {a.nom}</div>
|
<div><strong>Nom:</strong> {a.nom}</div>
|
||||||
<div><strong>Groupe:</strong> {a.groupe}</div>
|
<div><strong>Groupe:</strong> {a.groupes}</div>
|
||||||
<div><strong>Nombre de sessions:</strong> {stats.nbSessions}</div>
|
<div><strong>Nombre de sessions:</strong> {stats.nbSessions}</div>
|
||||||
<div><strong>Sessions/semaine:</strong> {stats.nbSessionsPerWeek.toFixed(2)}</div>
|
<div><strong>Sessions/semaine:</strong> {stats.nbSessionsPerWeek.toFixed(2)}</div>
|
||||||
<div><strong>Alerte:</strong> {alerte}</div>
|
<div><strong>Alerte:</strong> {alerte}</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useLocalData } from "../context/useLocalData";
|
import { useLocalData } from "../context/useLocalData";
|
||||||
import { Activite, Athlete, Coach , Session, Ligne, getUserTest } from "../classes";
|
import { Activite, Athlete, Coach , Session, Ligne, Admin } from "../classes";
|
||||||
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
|
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
|
||||||
import { keyboard } from "@testing-library/user-event/dist/keyboard";
|
import { keyboard } from "@testing-library/user-event/dist/keyboard";
|
||||||
import ObjectSession from "./object/session";
|
import ObjectSession from "./object/session";
|
||||||
@@ -10,14 +10,11 @@ import ObjectUser from "./object/user";
|
|||||||
export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes";
|
export type keyWord = "athletes" | "activites" | "coachs" | "sessions"| "lignes";
|
||||||
|
|
||||||
export default function RessourcePanel() {
|
export default function RessourcePanel() {
|
||||||
//const { user } = useLocalData();
|
const { user } = useLocalData();
|
||||||
const user = getUserTest(); //TODO
|
//const user = getUserTest(); //TODO
|
||||||
const [value,setValue] = useState<keyWord>("athletes");
|
const [value,setValue] = useState<keyWord>("athletes");
|
||||||
console.log("Rôle utilisateur:", user.role);
|
|
||||||
console.log(user.nom);
|
if (user instanceof Athlete) return null;
|
||||||
console.log(user.prenom);
|
|
||||||
console.log(user.email);
|
|
||||||
if (user.role === "athlete") return null;
|
|
||||||
|
|
||||||
|
|
||||||
const allAthletes: Athlete[] = [];
|
const allAthletes: Athlete[] = [];
|
||||||
@@ -28,26 +25,8 @@ import ObjectUser from "./object/user";
|
|||||||
|
|
||||||
const allSessions: Session[] = [];
|
const allSessions: Session[] = [];
|
||||||
|
|
||||||
const ligneMap: Map<number, Ligne> = new Map();
|
const allLignes: Ligne[] = [];
|
||||||
user.sessions.forEach(session => {
|
|
||||||
if (session.ligne) {
|
|
||||||
|
|
||||||
session.ligne.forEach(ligne => {
|
|
||||||
ligneMap.set(ligne.id, ligne);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const allLignes: Ligne[] = Array.from(ligneMap.values());
|
|
||||||
|
|
||||||
// Calculer le temps de jeu pour chaque ligne
|
|
||||||
const tempsDeJeuParLigne: Map<number, number> = new Map();
|
|
||||||
allLignes.forEach(ligne => {
|
|
||||||
const tempsTotal = calculTempsDeJeuParLigne(allSessions, ligne);
|
|
||||||
tempsDeJeuParLigne.set(ligne.id, tempsTotal);
|
|
||||||
ligne.tempsDeJeu = tempsTotal;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +42,7 @@ import ObjectUser from "./object/user";
|
|||||||
}}>
|
}}>
|
||||||
<option value="athletes">Athlètes</option>
|
<option value="athletes">Athlètes</option>
|
||||||
<option value="activites">Activités</option>
|
<option value="activites">Activités</option>
|
||||||
{user.role === "admin" && <option value="coachs"> Coachs</option>}
|
{user instanceof Admin && <option value="coachs"> Coachs</option>}
|
||||||
<option value="sessions"> Sessions</option>
|
<option value="sessions"> Sessions</option>
|
||||||
<option value="lignes"> Lignes</option>
|
<option value="lignes"> Lignes</option>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import api, { activiteService, sessionService } from "./api";
|
import api, { activiteService, sessionService } from "./api";
|
||||||
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
import { Activite, Admin, Athlete, Coach, Session, User } from "./classes";
|
||||||
import Keycloak from 'keycloak-js'
|
import Keycloak from 'keycloak-js'
|
||||||
|
import { AdminDTO, AthleteDTO, CoachDTO } from "./classesDTO";
|
||||||
|
|
||||||
//debug:
|
//debug:
|
||||||
export function delay(ms: number): Promise<void> {
|
export function delay(ms: number): Promise<void> {
|
||||||
@@ -19,16 +20,19 @@ export async function getUser(keycloak:Keycloak): Promise<User|null>{
|
|||||||
const roles = keycloak.tokenParsed?.realm_access?.roles
|
const roles = keycloak.tokenParsed?.realm_access?.roles
|
||||||
if(roles!=null){
|
if(roles!=null){
|
||||||
if(roles.includes("admin")){
|
if(roles.includes("admin")){
|
||||||
const response = await api.get<any>(`/TODO`);
|
const response = await api.get<AdminDTO>(`/TODO`);
|
||||||
return response.data;
|
const admin = new Admin(response.data);
|
||||||
|
return admin;
|
||||||
}
|
}
|
||||||
else if(roles.includes("coach")){
|
else if(roles.includes("coach")){
|
||||||
const response = await api.get<any>(`/TODO`);
|
const response = await api.get<CoachDTO>(`/TODO`);
|
||||||
return response.data;
|
const coach = new Coach(response.data);
|
||||||
|
return coach;
|
||||||
}
|
}
|
||||||
else if(roles.includes("athletes")){
|
else if(roles.includes("athletes")){
|
||||||
const response = await api.get<any>(`/TODO`);
|
const response = await api.get<AthleteDTO>(`/TODO`);
|
||||||
return response.data;
|
const athlete = new Athlete(response.data);
|
||||||
|
return athlete;
|
||||||
}
|
}
|
||||||
console.error("Error roles inconnu");
|
console.error("Error roles inconnu");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user