Merge remote-tracking branch 'origin/main'
This commit is contained in:
6
back_end/package-lock.json
generated
Normal file
6
back_end/package-lock.json
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "back_end",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
||||||
@@ -6,11 +6,15 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.CorsConfigurationSource;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@@ -19,9 +23,10 @@ public class WebSecurityConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http
|
||||||
|
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||||
.csrf(csrf -> csrf.disable())
|
.csrf(csrf -> csrf.disable())
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/", "/public", "/coach/**").permitAll() // allow coach endpoints
|
.requestMatchers(HttpMethod.OPTIONS, "/", "/public", "/coach/**").permitAll() // allow coach endpoints
|
||||||
.requestMatchers("/admin/**").hasRole("admin")
|
.requestMatchers("/admin/**").hasRole("admin")
|
||||||
.requestMatchers("/user/**").hasRole("user")
|
.requestMatchers("/user/**").hasRole("user")
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
@@ -29,6 +34,7 @@ public class WebSecurityConfig {
|
|||||||
.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtToken -> {
|
.jwt(jwt -> jwt.jwtAuthenticationConverter(jwtToken -> {
|
||||||
Map<String, Collection<String>> realmAccess = jwtToken.getClaim("realm_access");
|
Map<String, Collection<String>> realmAccess = jwtToken.getClaim("realm_access");
|
||||||
Collection<String> roles = realmAccess.get("roles");
|
Collection<String> roles = realmAccess.get("roles");
|
||||||
|
System.out.println("ROLES FROM TOKEN " + roles);
|
||||||
List<SimpleGrantedAuthority> authorities = roles.stream()
|
List<SimpleGrantedAuthority> authorities = roles.stream()
|
||||||
.map(role -> new SimpleGrantedAuthority("ROLE_" + role))
|
.map(role -> new SimpleGrantedAuthority("ROLE_" + role))
|
||||||
.toList();
|
.toList();
|
||||||
@@ -37,4 +43,18 @@ public class WebSecurityConfig {
|
|||||||
|
|
||||||
return http.build();
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsConfigurationSource corsConfigurationSource() {
|
||||||
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
config.setAllowedOrigins(List.of("http://localhost:3000"));
|
||||||
|
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
|
||||||
|
config.setAllowCredentials(true);
|
||||||
|
config.setAllowedHeaders(List.of("Authorization", "Content-Type"));
|
||||||
|
UrlBasedCorsConfigurationSource source =
|
||||||
|
new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", config);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import jakarta.persistence.Entity;
|
|||||||
public class Admin extends User{
|
public class Admin extends User{
|
||||||
|
|
||||||
public Admin(String id_keycloak, String name, String prenom){
|
public Admin(String id_keycloak, String name, String prenom){
|
||||||
super(name, id_keycloak, prenom, Role.ADMIN );
|
super(name, id_keycloak, prenom, Role.admin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class Athlete extends User{
|
|||||||
private List<Session> sessions = new ArrayList<>(); // plusieurs sessions sont possibles
|
private List<Session> sessions = new ArrayList<>(); // plusieurs sessions sont possibles
|
||||||
|
|
||||||
public Athlete(String name, String id_keycloak, String prenom){
|
public Athlete(String name, String id_keycloak, String prenom){
|
||||||
super(name, id_keycloak, prenom, Role.ATHLETE);
|
super(name, id_keycloak, prenom, Role.athlete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class Coach extends User{
|
|||||||
private List<Session> sessions = new ArrayList<>(); // Un coach peut avoir plusieurs sessions
|
private List<Session> sessions = new ArrayList<>(); // Un coach peut avoir plusieurs sessions
|
||||||
|
|
||||||
public Coach(String name, String id_keycloak, String prenom){
|
public Coach(String name, String id_keycloak, String prenom){
|
||||||
super(name, id_keycloak, prenom, Role.COACH );
|
super(name, id_keycloak, prenom, Role.coach );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package hackathon.FrisbYEE.jpa.metier;
|
package hackathon.FrisbYEE.jpa.metier;
|
||||||
|
|
||||||
public enum Role {
|
public enum Role {
|
||||||
ADMIN,
|
admin,
|
||||||
COACH,
|
coach,
|
||||||
ATHLETE
|
athlete
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ public class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCoach(Coach coach) {
|
public void setCoach(Coach coach) {
|
||||||
if (coach.getRole() != Role.COACH) {
|
if (coach.getRole() != Role.coach) {
|
||||||
throw new IllegalArgumentException("L'utilisateur n'est pas un coach");
|
throw new IllegalArgumentException("L'utilisateur n'est pas un coach");
|
||||||
}
|
}
|
||||||
this.coach = coach;
|
this.coach = coach;
|
||||||
@@ -66,7 +66,7 @@ public class Session {
|
|||||||
|
|
||||||
public void setAthletes(List<Athlete> athletes) {
|
public void setAthletes(List<Athlete> athletes) {
|
||||||
for (Athlete athlete : athletes) {
|
for (Athlete athlete : athletes) {
|
||||||
if (athlete.getRole() != Role.ATHLETE) {
|
if (athlete.getRole() != Role.athlete) {
|
||||||
throw new IllegalArgumentException("L'utilisateur n'est pas un athlète");
|
throw new IllegalArgumentException("L'utilisateur n'est pas un athlète");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@CrossOrigin(origins = "http://localhost:3000")
|
@CrossOrigin(origins = "http://localhost:3000")
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/activite")
|
@RequestMapping("/activite")
|
||||||
@@ -49,6 +50,7 @@ public class ActiviteResource {
|
|||||||
public ResponseEntity<String> create(@RequestBody ActiviteDTO dto) {
|
public ResponseEntity<String> create(@RequestBody ActiviteDTO dto) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.println("ROLE TEST " + hackathon.FrisbYEE.jpa.metier.Role.coach);
|
||||||
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
||||||
Activite activite = mapToEntity(dto);
|
Activite activite = mapToEntity(dto);
|
||||||
activite.setSession(session);
|
activite.setSession(session);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"realm": "Frisbyee_realm",
|
"realm": "Frisbyee_realm",
|
||||||
"resource": "Frisbyee_client",
|
"resource": "Frisbyee_client",
|
||||||
|
"clientId": "Frisbyee_client",
|
||||||
"auth-server-url": "http://localhost:8080",
|
"auth-server-url": "http://localhost:8080",
|
||||||
"public-client": true
|
"public-client": true
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@ const api = axios.create({
|
|||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
api.interceptors.request.use((config) => {
|
api.interceptors.request.use((config) => {
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ export function getUserTest():User{
|
|||||||
s1.isRecurrent = true;
|
s1.isRecurrent = true;
|
||||||
s1.ligne = [ligne1];
|
s1.ligne = [ligne1];
|
||||||
s1.duree= 90;
|
s1.duree= 90;
|
||||||
|
s1.athletes = [athlete1,athlete2];
|
||||||
var date2 = new Date();
|
var date2 = new Date();
|
||||||
date2.setDate(date2.getDate() + 2);
|
date2.setDate(date2.getDate() + 2);
|
||||||
s2.creneau = date2;
|
s2.creneau = date2;
|
||||||
@@ -113,19 +114,15 @@ export function getUserTest():User{
|
|||||||
s2.name = "entraintement 2"
|
s2.name = "entraintement 2"
|
||||||
s2.ligne = [ligne2];
|
s2.ligne = [ligne2];
|
||||||
s2.duree= 120;
|
s2.duree= 120;
|
||||||
|
s2.athletes = [athlete1,athlete2, athlete3];
|
||||||
|
|
||||||
s3.creneau = date2;
|
s3.creneau = date2;
|
||||||
s3.id = 3;
|
s3.id = 3;
|
||||||
s3.isRecurrent = false;
|
s3.isRecurrent = false;
|
||||||
s3.name = "entraintement 3"
|
s3.name = "entraintement 3"
|
||||||
s3.ligne = [ligne3, ligne1];
|
s3.ligne = [ligne3, ligne1];
|
||||||
s3.duree= 120;
|
s3.duree= 120;
|
||||||
|
s3.athletes = [athlete2, athlete3];
|
||||||
|
|
||||||
|
|
||||||
s1.athletes = [athlete1, athlete2];
|
|
||||||
s2.athletes = [athlete2, athlete3];
|
|
||||||
s3.athletes = [athlete1, athlete3];
|
|
||||||
|
|
||||||
|
|
||||||
const act1 = new Activite();
|
const act1 = new Activite();
|
||||||
act1.id = 1;
|
act1.id = 1;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Session, User, Coach, Activite, Groupe } from "../classes";
|
import { Session, User, Coach, Activite, Groupe } from "../classes";
|
||||||
import { useLocalData } from "../context/useLocalData";
|
import { useLocalData } from "../context/useLocalData";
|
||||||
import { sessionService } from "../api";
|
import { activiteService, sessionService } from "../api";
|
||||||
|
|
||||||
export const CreateSession = () => {
|
export const CreateSession = () => {
|
||||||
const {user} = useLocalData()
|
const {user} = useLocalData()
|
||||||
@@ -24,7 +24,7 @@ export const CreateSession = () => {
|
|||||||
newActivite.duree= activiteDuree;
|
newActivite.duree= activiteDuree;
|
||||||
newActivite.data= new Map<string,string>();
|
newActivite.data= new Map<string,string>();
|
||||||
try{
|
try{
|
||||||
await sessionService.create(newActivite);
|
await activiteService.create(newActivite);
|
||||||
console.log("Session créée");
|
console.log("Session créée");
|
||||||
|
|
||||||
setActivities([...activities, newActivite]);
|
setActivities([...activities, newActivite]);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export const Login =() =>{
|
|||||||
|
|
||||||
|
|
||||||
function handleLogin(): void {
|
function handleLogin(): void {
|
||||||
keycloak.login()
|
keycloak.login();
|
||||||
//TODO setUser
|
//TODO setUser
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +80,9 @@ export const Login =() =>{
|
|||||||
<div>
|
<div>
|
||||||
User nom : { user.nom}
|
User nom : { user.nom}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
User role : { user.role}
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,82 @@
|
|||||||
|
import React from "react";
|
||||||
import { Athlete, Activite, Coach, Session, Ligne } from "../classes";
|
import { Athlete, Activite, Coach, Session, Ligne } from "../classes";
|
||||||
|
import {calculStatsAthlete, niveauAlerte} from "../utils/athleteUtils";
|
||||||
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
|
import {calculTempsDeJeuParLigne} from "../utils/ligneUtils";
|
||||||
|
|
||||||
|
|
||||||
type AthleteListProps = { athletes: Athlete[] };
|
type AthleteListProps = { athletes: Athlete[], sessions: Session[]};
|
||||||
type ActiviteListProps = { activites: Activite[] };
|
type ActiviteListProps = { activites: Activite[] };
|
||||||
type CoachListProps = { coachs: Coach[] };
|
type CoachListProps = { coachs: Coach[] };
|
||||||
type SessionListProps = { sessions: Session[]};
|
type SessionListProps = { sessions: Session[]};
|
||||||
type LigneListProps = { lignes: Ligne[], tempsDeJeuParLigne: Map<number, number> };
|
type LigneListProps = { lignes: Ligne[], tempsDeJeuParLigne: Map<number, number> };
|
||||||
|
|
||||||
function AthleteList({ athletes }: AthleteListProps) {
|
function AthleteList({ athletes, sessions }: AthleteListProps) {
|
||||||
|
const [dateDebut, setDateDebut] = React.useState(new Date());
|
||||||
|
const [dateFin, setDateFin] = React.useState(new Date());
|
||||||
|
const [seuilCritique, setSeuilCritique] = React.useState(0);
|
||||||
|
const [seuilMax, setSeuilMax] = React.useState(0);
|
||||||
|
|
||||||
|
const dateToDatetimeLocal = (date: Date) => {
|
||||||
|
const pad = (n: number) => n.toString().padStart(2, "0");
|
||||||
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className="AthleteList">
|
<>
|
||||||
{athletes.map((athlete) => (
|
<div className="creneau-stats">
|
||||||
<li key={athlete.id}>
|
<label>
|
||||||
<div><strong>Nom:</strong> {athlete.nom}</div>
|
Début :
|
||||||
<div><strong>Groupe:</strong> {athlete.groupe}</div>
|
<input
|
||||||
</li>
|
type="datetime-local"
|
||||||
))}
|
value={dateToDatetimeLocal(dateDebut)}
|
||||||
</ul>
|
onChange={e => setDateDebut(new Date(e.target.value))}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
Fin :
|
||||||
|
<input
|
||||||
|
type="datetime-local"
|
||||||
|
value={dateToDatetimeLocal(dateFin)}
|
||||||
|
onChange={e => setDateFin(new Date(e.target.value))}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Seuil critique :
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={seuilCritique}
|
||||||
|
min={1}
|
||||||
|
onChange={e => setSeuilCritique(Number(e.target.value))}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label>Seuil max :
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={seuilMax}
|
||||||
|
min={1}
|
||||||
|
onChange={e => setSeuilMax(Number(e.target.value))}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul className="AthleteList">
|
||||||
|
{athletes.map(a => {
|
||||||
|
const stats = calculStatsAthlete(sessions, a, dateDebut, dateFin);
|
||||||
|
const alerte = niveauAlerte(stats, seuilCritique, seuilMax);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li key={a.id}>
|
||||||
|
<div><strong>Nom:</strong> {a.nom}</div>
|
||||||
|
<div><strong>Groupe:</strong> {a.groupe}</div>
|
||||||
|
<div><strong>Nombre de sessions:</strong> {stats.nbSessions}</div>
|
||||||
|
<div><strong>Sessions/semaine:</strong> {stats.nbSessionsPerWeek.toFixed(2)}</div>
|
||||||
|
<div><strong>Alerte:</strong> {alerte}</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ import { unescapeLeadingUnderscores } from "typescript";
|
|||||||
{value==="athletes" && (
|
{value==="athletes" && (
|
||||||
<div className="edt_athletes_panel">
|
<div className="edt_athletes_panel">
|
||||||
<h3>Liste des athlètes</h3>
|
<h3>Liste des athlètes</h3>
|
||||||
<AthleteList athletes={allAthletes} />
|
<AthleteList athletes={allAthletes} sessions={allSessions} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
46
front_end/src/utils/athleteUtils.tsx
Normal file
46
front_end/src/utils/athleteUtils.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { Athlete, Session } from '../classes';
|
||||||
|
|
||||||
|
export interface StatsAthlete {
|
||||||
|
nbSessions: number;
|
||||||
|
nbSessionsPerWeek: number;
|
||||||
|
isAlerte: boolean;
|
||||||
|
distributions: Map<string, number>; //le nom de l'activité et son nombre
|
||||||
|
}
|
||||||
|
|
||||||
|
export function niveauAlerte(stats: StatsAthlete, seuilCritique = 0, seuilMax = 0) {
|
||||||
|
if (stats.nbSessionsPerWeek > seuilMax) return "Alerte ! Niveau maximal atteint.";
|
||||||
|
if (stats.nbSessionsPerWeek > seuilCritique) return "Attention! Niveau critique atteint.";
|
||||||
|
return "Normal";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function calculStatsAthlete(sessions: Session[], athlete: Athlete, debut: Date, fin: Date): StatsAthlete {
|
||||||
|
let nb_sessions = 0;
|
||||||
|
let nb_semaine = 1; //forcément une semaine
|
||||||
|
const distributions: Map<string, number> = new Map();
|
||||||
|
const timeDiff = Math.abs(fin.getTime() - debut.getTime());
|
||||||
|
nb_semaine = Math.ceil(timeDiff / (1000 * 3600 * 24 * 7));
|
||||||
|
|
||||||
|
sessions.forEach(session => {
|
||||||
|
// verification session dans l'intervalle
|
||||||
|
if (session.creneau < debut || session.creneau > fin) return;
|
||||||
|
|
||||||
|
// verification athlete dans session
|
||||||
|
if (!session.athletes.some(a => a.id === athlete.id)) return;
|
||||||
|
|
||||||
|
//incrementation (verifie si recurent ou non)
|
||||||
|
const increment = session.isRecurrent ? nb_semaine : 1;
|
||||||
|
nb_sessions += increment;
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const nbSessionsPerWeek = nb_sessions / nb_semaine;
|
||||||
|
const isAlerte = nbSessionsPerWeek > 8;
|
||||||
|
|
||||||
|
return {
|
||||||
|
nbSessions: nb_sessions,
|
||||||
|
nbSessionsPerWeek: nbSessionsPerWeek,
|
||||||
|
isAlerte: isAlerte,
|
||||||
|
distributions: distributions
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user