merge
This commit is contained in:
@@ -3,6 +3,8 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AdminDTO {
|
||||
private String id_keycloak;
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String name;
|
||||
private String prenom;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AthleteDTO {
|
||||
private Integer id;
|
||||
private String id_keycloak;
|
||||
private String name;
|
||||
private String prenom;
|
||||
private String categorie;
|
||||
private String niveau;
|
||||
private List<String> groupes = new ArrayList<>();
|
||||
private List<Integer> sessionIds = new ArrayList<>();
|
||||
private Integer userId;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package hackathon.FrisbYEE.jpa.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CoachDTO {
|
||||
private Integer id;
|
||||
private String id_keycloak;
|
||||
private String name;
|
||||
|
||||
private String prenom;
|
||||
private List<Integer> sessionIds;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
@Data
|
||||
public class SessionDTO {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Boolean isRecurrent;
|
||||
private LocalDateTime creneau;
|
||||
|
||||
@@ -5,8 +5,9 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDTO {
|
||||
private Integer id;
|
||||
private String id_keycloak;
|
||||
private String name;
|
||||
private String prenom;
|
||||
private String email;
|
||||
private Role role;
|
||||
}
|
||||
|
||||
@@ -14,21 +14,14 @@ import jakarta.persistence.Entity;
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
@Access(AccessType.FIELD)
|
||||
|
||||
public class Admin {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
public class Admin extends User{
|
||||
|
||||
@OneToOne(mappedBy = "admin")
|
||||
private User user;
|
||||
|
||||
public Admin(String name){
|
||||
this.name = name;
|
||||
public Admin(String id_keycloak, String name, String prenom){
|
||||
super(name, id_keycloak, prenom, Role.ADMIN );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Admin [id=" + id + " , name=" + name + "]";
|
||||
return "Admin [id=" + super.getId() + " , name=" + super.getName() + "]";
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,8 @@ import jakarta.persistence.Entity;
|
||||
@Data @NoArgsConstructor
|
||||
@Access(AccessType.FIELD)
|
||||
|
||||
public class Athlete {
|
||||
public class Athlete extends User{
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String categorie;
|
||||
private String niveau;
|
||||
@ElementCollection
|
||||
@@ -32,22 +28,12 @@ public class Athlete {
|
||||
@ManyToMany(mappedBy = "athletes")
|
||||
private List<Session> sessions = new ArrayList<>(); // plusieurs sessions sont possibles
|
||||
|
||||
@OneToOne(mappedBy = "athlete")
|
||||
private User user;
|
||||
|
||||
public Athlete(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Athlete(String name, String categorie, String niveau, List<String> groupe){
|
||||
this.name = name;
|
||||
this.categorie = categorie;
|
||||
this.niveau = niveau;
|
||||
this.groupe = groupe;
|
||||
public Athlete(String name, String id_keycloak, String prenom){
|
||||
super(name, id_keycloak, prenom, Role.ATHLETE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Athlete [id=" + id + " , name=" + name + "]";
|
||||
return "Athlete [id=" + super.getId() + " , name=" + super.getName() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,24 +17,17 @@ import jakarta.persistence.Entity;
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
@Access(AccessType.FIELD)
|
||||
|
||||
public class Coach {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
public class Coach extends User{
|
||||
|
||||
@OneToMany(mappedBy = "coach")
|
||||
private List<Session> sessions = new ArrayList<>(); // Un coach peut avoir plusieurs sessions
|
||||
|
||||
@OneToOne(mappedBy = "coach")
|
||||
private User user;
|
||||
|
||||
public Coach(String name){
|
||||
this.name = name;
|
||||
public Coach(String name, String id_keycloak, String prenom){
|
||||
super(name, id_keycloak, prenom, Role.COACH );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Coach [id=" + id + " , name=" + name + "]";
|
||||
return "Coach [id=" + super.getId() + " , name=" + super.getName() + "]";
|
||||
}
|
||||
}
|
||||
@@ -56,4 +56,21 @@ public class Session {
|
||||
public String toString() {
|
||||
return "Session [id=" + id + " , name=" + name + "]";
|
||||
}
|
||||
|
||||
public void setCoach(Coach coach) {
|
||||
if (coach.getRole() != Role.COACH) {
|
||||
throw new IllegalArgumentException("L'utilisateur n'est pas un coach");
|
||||
}
|
||||
this.coach = coach;
|
||||
}
|
||||
|
||||
public void setAthletes(List<Athlete> athletes) {
|
||||
for (Athlete athlete : athletes) {
|
||||
if (athlete.getRole() != Role.ATHLETE) {
|
||||
throw new IllegalArgumentException("L'utilisateur n'est pas un athlète");
|
||||
}
|
||||
}
|
||||
this.athletes = athletes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,34 +26,22 @@ public class User implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(unique = true, nullable = false)
|
||||
private Integer id;
|
||||
@Column(unique = true, nullable = false) // pas possible d'avoir le même nom
|
||||
@Column(nullable = false, unique = true)
|
||||
private String id_keycloak;
|
||||
|
||||
private String name;
|
||||
@Column(nullable = false)
|
||||
private String motDePasse;
|
||||
private String email;
|
||||
private String prenom;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private Role role;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private Coach coach;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private Athlete athlete;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private Admin admin;
|
||||
|
||||
public User(String name) {
|
||||
public User(String name, String id_keycloak, String prenom, Role role) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public User(String name, String motDePasse, String email, Role role) {
|
||||
this.name = name;
|
||||
this.motDePasse = motDePasse;
|
||||
this.email = email;
|
||||
this.id_keycloak = id_keycloak;
|
||||
this.prenom = prenom;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package hackathon.FrisbYEE.jpa.metier;
|
||||
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.MapsId;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "utilisateur_role")
|
||||
public class UserRole {
|
||||
|
||||
@EmbeddedId
|
||||
private UserRoleId id;
|
||||
|
||||
@ManyToOne
|
||||
@MapsId("utilisateurId")
|
||||
private User utilisateur;
|
||||
|
||||
@ManyToOne
|
||||
@MapsId("roleId")
|
||||
private Role role;
|
||||
|
||||
// getters/setters
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package hackathon.FrisbYEE.jpa.metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class UserRoleId implements Serializable {
|
||||
|
||||
private Long utilisateurId;
|
||||
private Long roleId;
|
||||
|
||||
// equals() & hashCode() OBLIGATOIRES
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package hackathon.FrisbYEE.jpa.metier;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.MapsId;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Inheritance(strategy = jakarta.persistence.InheritanceType.JOINED)
|
||||
@Table(name = "utilisateur_role_details")
|
||||
public abstract class UtilisateurRoleDetails {
|
||||
|
||||
@Id
|
||||
private Long utilisateurId;
|
||||
|
||||
@OneToOne
|
||||
@MapsId
|
||||
@JoinColumn(name = "utilisateur_id")
|
||||
private User utilisateur;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package hackathon.FrisbYEE.jpa.service;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.metier.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UserDAO extends JpaRepository<User, Integer> {
|
||||
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class AthleteResource {
|
||||
|
||||
private AthleteDTO mapToDTO(Athlete athlete) {
|
||||
AthleteDTO dto = new AthleteDTO();
|
||||
dto.setId(athlete.getId());
|
||||
dto.setId_keycloak(athlete.getId_keycloak());
|
||||
dto.setName(athlete.getName());
|
||||
dto.setCategorie(athlete.getCategorie());
|
||||
dto.setNiveau(athlete.getNiveau());
|
||||
@@ -135,10 +135,6 @@ public class AthleteResource {
|
||||
|
||||
private Athlete mapToEntity(AthleteDTO dto) {
|
||||
Athlete athlete = new Athlete();
|
||||
athlete.setId(dto.getId());
|
||||
athlete.setName(dto.getName());
|
||||
athlete.setCategorie(dto.getCategorie());
|
||||
athlete.setNiveau(dto.getNiveau());
|
||||
return athlete;
|
||||
}
|
||||
|
||||
@@ -156,7 +152,6 @@ public class AthleteResource {
|
||||
for (Session s : sessions) {
|
||||
if (s.getAthletes().contains(j.get())) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(s.getId());
|
||||
dto.setName(s.getName());
|
||||
// Map other fields as necessary
|
||||
athleteSessions.add(dto);
|
||||
@@ -177,7 +172,6 @@ public class AthleteResource {
|
||||
List<SessionDTO> sessionDTOs = new ArrayList<>();
|
||||
for (Session session : sessions) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(session.getId());
|
||||
dto.setName(session.getName());
|
||||
// Map other fields as necessary
|
||||
sessionDTOs.add(dto);
|
||||
@@ -229,7 +223,6 @@ public class AthleteResource {
|
||||
// sympa les
|
||||
// dates
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(session.getId());
|
||||
dto.setName(session.getName());
|
||||
// Map other fields as necessary
|
||||
filteredSessions.add(dto);
|
||||
@@ -259,7 +252,6 @@ public class AthleteResource {
|
||||
&& session.getCreneau().isAfter(ChronoLocalDateTime.from(LocalDate.parse(startDate)))
|
||||
&& session.getCreneau().isBefore(ChronoLocalDateTime.from(LocalDate.parse(endDate)))) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(session.getId());
|
||||
dto.setName(session.getName());
|
||||
// Map other fields as necessary
|
||||
filteredSessions.add(dto);
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
@@ -71,14 +70,14 @@ public class CoachResource {
|
||||
|
||||
private CoachDTO mapToDTO(Coach coach) {
|
||||
CoachDTO dto = new CoachDTO();
|
||||
dto.setId(coach.getId());
|
||||
dto.setId_keycloak(coach.getId_keycloak());
|
||||
dto.setName(coach.getName());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Coach mapToEntity(CoachDTO dto) {
|
||||
Coach coach = new Coach();
|
||||
coach.setId(dto.getId());
|
||||
coach.setId_keycloak(dto.getId_keycloak());
|
||||
coach.setName(dto.getName());
|
||||
return coach;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import hackathon.FrisbYEE.jpa.service.ActiviteDAO;
|
||||
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
||||
import hackathon.FrisbYEE.jpa.service.CoachDAO;
|
||||
import hackathon.FrisbYEE.jpa.service.SessionDAO;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -109,7 +110,6 @@ public class SessionResource {
|
||||
|
||||
private SessionDTO maptoDTO(Session s) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
dto.setId(s.getId());
|
||||
dto.setName(s.getName());
|
||||
dto.setIsRecurrent(s.getIsRecurrent());
|
||||
dto.setCreneau(s.getCreneau());
|
||||
@@ -140,7 +140,6 @@ public class SessionResource {
|
||||
|
||||
private Session maptoEntity(SessionDTO dto) {
|
||||
Session session = new Session();
|
||||
session.setId(dto.getId());
|
||||
session.setName(dto.getName());
|
||||
session.setIsRecurrent(dto.getIsRecurrent());
|
||||
session.setCreneau(dto.getCreneau());
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
||||
export type Role = "Admin" | "Athlete" | "Coach";
|
||||
|
||||
export class User{
|
||||
id!: number;
|
||||
nom!: String;
|
||||
sessions: Session[] = []; //nb: Admin liaison non symétrique /!\
|
||||
email!: String;
|
||||
role!: Role;
|
||||
}
|
||||
|
||||
export class Admin extends User{
|
||||
role!: Role;
|
||||
|
||||
}
|
||||
|
||||
export class Athlete extends User{
|
||||
nom!: String;
|
||||
groupe!: Groupe;
|
||||
role!: Role;
|
||||
|
||||
|
||||
}
|
||||
|
||||
export class Coach extends User{
|
||||
nom!: String;
|
||||
role!: Role;
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +57,7 @@ export function getUserTest():User{
|
||||
const s3 = new Session();
|
||||
user.id = 0;
|
||||
user.nom = "Emilien-Yee NootNoot";
|
||||
user.role = "Coach"
|
||||
s1.creneau = new Date();
|
||||
s1.id = 1;
|
||||
s1.name = "Entrainement Frisbee"
|
||||
@@ -145,5 +153,10 @@ export function getUserTest():User{
|
||||
user.sessions.push(s1);
|
||||
user.sessions.push(s2);
|
||||
user.sessions.push(s3);
|
||||
|
||||
athlete1.role = "Athlete";
|
||||
athlete2.role = "Athlete";
|
||||
athlete3.role = "Athlete";
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export const CreateSession = () => {
|
||||
const [activiteDuree, setActiviteDuree] = useState(0);
|
||||
const [isRecurent, setIsRecurent] = useState(false);
|
||||
|
||||
function addAcitivte(){
|
||||
async function addAcitivte(){
|
||||
if (!activiteNom) return;
|
||||
|
||||
const newActivite = new Activite();
|
||||
@@ -23,11 +23,18 @@ export const CreateSession = () => {
|
||||
newActivite.theme=activiteTheme;
|
||||
newActivite.duree= activiteDuree;
|
||||
newActivite.data= new Map<string,string>();
|
||||
setActivities([...activities, newActivite]);
|
||||
try{
|
||||
await sessionService.create(newActivite);
|
||||
console.log("Session créée");
|
||||
|
||||
setActiviteNom("");
|
||||
setActiviteTheme("");
|
||||
setActiviteDuree(0);
|
||||
setActivities([...activities, newActivite]);
|
||||
|
||||
setActiviteNom("");
|
||||
setActiviteTheme("");
|
||||
setActiviteDuree(0);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la création de la session", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateSession() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Athlete, Activite } from "../classes";
|
||||
import { Athlete, Activite, Coach, Session } from "../classes";
|
||||
|
||||
type Props = {
|
||||
athletes: Athlete[];
|
||||
activites: Activite[];
|
||||
type AthleteListProps = { athletes: Athlete[] };
|
||||
type ActiviteListProps = { activites: Activite[] };
|
||||
type CoachListProps = { coachs: Coach[] };
|
||||
type SessionListProps = { sessions: Session[]};
|
||||
|
||||
};
|
||||
|
||||
function AthleteList({ athletes }: Props) {
|
||||
function AthleteList({ athletes }: AthleteListProps) {
|
||||
return (
|
||||
<ul className="AthleteList">
|
||||
{athletes.map((athlete) => (
|
||||
@@ -19,7 +18,7 @@ function AthleteList({ athletes }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
function ActiviteList({ activites }: Props) {
|
||||
function ActiviteList({ activites }: ActiviteListProps) {
|
||||
return (
|
||||
<ul className="ActiviteList">
|
||||
{activites.map((activite) => (
|
||||
@@ -39,4 +38,43 @@ function ActiviteList({ activites }: Props) {
|
||||
);
|
||||
}
|
||||
|
||||
export { AthleteList, ActiviteList };
|
||||
function CoachList({ coachs }: CoachListProps) {
|
||||
return (
|
||||
<ul className="CoachList">
|
||||
{coachs.map((coachs) => (
|
||||
<li key={coachs.id}>
|
||||
<div>
|
||||
<strong>Nom:</strong> {coachs.nom}
|
||||
</div>
|
||||
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
function SessionList({ sessions }: SessionListProps) {
|
||||
return (
|
||||
<ul className="SessionList">
|
||||
{sessions.map((sessions) => (
|
||||
<li key={sessions.id}>
|
||||
<div>
|
||||
<strong>Nom:</strong> {sessions.name}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Groupe:</strong> {sessions.groupe}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Recurrent:</strong> {sessions.isRecurrent ? "Oui" : "Non"}
|
||||
</div>
|
||||
<div>
|
||||
<strong>Coach:</strong> {sessions.coach ? sessions.coach.nom : "Pas de coach sur la séance"}
|
||||
</div>
|
||||
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export { AthleteList, ActiviteList, CoachList , SessionList };
|
||||
@@ -1,13 +1,16 @@
|
||||
import { useState } from "react";
|
||||
import { useLocalData } from "../context/useLocalData";
|
||||
import { AthleteList, ActiviteList } from "./ressourceList";
|
||||
import { Activite, Athlete } from "../classes";
|
||||
// import { Dropdown } from "react-bootstrap"; // not used
|
||||
import { AthleteList, ActiviteList, CoachList, SessionList} from "./ressourceList";
|
||||
import { Activite, Athlete, Coach , Session } from "../classes";
|
||||
|
||||
export default function RessourcePanel() {
|
||||
const { user } = useLocalData();
|
||||
const [showAthletes, setShowAthletes] = useState(false);
|
||||
const [showActivites, setShowActivites] = useState(false);
|
||||
const [showCoachs,setShowCoachs] = useState(false);
|
||||
const [showSessions, setShowSessions] = useState(false);
|
||||
console.log("Rôle utilisateur:", user.role);
|
||||
if (user.role === "Athlete") return null;
|
||||
|
||||
|
||||
const athleteMap: Map<number, Athlete> = new Map();
|
||||
@@ -22,13 +25,51 @@ export default function RessourcePanel() {
|
||||
});
|
||||
const allActivites: Activite[] = Array.from(activiteMap.values());
|
||||
|
||||
const coachMap: Map<number, Coach> = new Map();
|
||||
user.sessions.forEach(session => {
|
||||
if (session.coach) {
|
||||
coachMap.set(session.coach.id, session.coach);
|
||||
}
|
||||
});
|
||||
|
||||
const allCoachs: Coach[] = Array.from(coachMap.values());
|
||||
|
||||
const sessionMap: Map<number, Session> = new Map();
|
||||
user.sessions.forEach(session => {
|
||||
sessionMap.set(session.id, session);
|
||||
});
|
||||
|
||||
const allSessions: Session[] = Array.from(sessionMap.values());
|
||||
|
||||
function onAthletesClick(): void {
|
||||
setShowAthletes(prev => !prev);
|
||||
setShowActivites(false);
|
||||
setShowCoachs(false);
|
||||
setShowSessions(false);
|
||||
|
||||
}
|
||||
function onActivitiesClick(): void {
|
||||
setShowActivites(prev => !prev);
|
||||
setShowAthletes(false);
|
||||
setShowCoachs(false);
|
||||
setShowSessions(false);
|
||||
|
||||
|
||||
}
|
||||
function onCoachClick(): void {
|
||||
setShowCoachs(prev => !prev);
|
||||
setShowActivites(false);
|
||||
setShowAthletes(false);
|
||||
setShowSessions(false);
|
||||
|
||||
}
|
||||
|
||||
function onSessionClick(): void {
|
||||
setShowSessions(prev => !prev);
|
||||
setShowActivites(false);
|
||||
setShowAthletes(false);
|
||||
setShowCoachs(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,28 +80,46 @@ export default function RessourcePanel() {
|
||||
const v = (e.target as HTMLSelectElement).value;
|
||||
if (v === "athletes") onAthletesClick();
|
||||
else if (v === "activites") onActivitiesClick();
|
||||
else {setShowAthletes(false); setShowActivites(false);
|
||||
}
|
||||
else if (v === "coach") onCoachClick();
|
||||
else if (v === "session") onSessionClick();
|
||||
else {setShowAthletes(false); setShowActivites(false); setShowCoachs(false); setShowSessions(false)}
|
||||
}}>
|
||||
<option>Choissisez la ressource</option>
|
||||
<option value="athletes">Athlètes</option>
|
||||
<option value="activites">Activités</option>
|
||||
{user.role === "Admin" && <option value="coach"> Coach</option>}
|
||||
<option value="session"> Session</option>
|
||||
</select>
|
||||
|
||||
{showAthletes && (
|
||||
<div className="edt_athletes_panel">
|
||||
<h3>Liste des athlètes</h3>
|
||||
<AthleteList athletes={allAthletes} activites={[]}/>
|
||||
<AthleteList athletes={allAthletes} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showActivites && (
|
||||
<div className="edt_activites_panel">
|
||||
<h3>Liste des activités</h3>
|
||||
<ActiviteList athletes={[]} activites={allActivites} />
|
||||
<ActiviteList activites={allActivites} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showCoachs && (
|
||||
<div className="edt_coachs_panel">
|
||||
<h3>Liste des coachs</h3>
|
||||
<CoachList coachs={allCoachs} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showSessions && (
|
||||
<div className="edt_sessions_panel">
|
||||
<h3>Liste des sessions</h3>
|
||||
<SessionList sessions={allSessions} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
20
front_end/src/components/test_app.tsx
Normal file
20
front_end/src/components/test_app.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import React, { useState } from "react";
|
||||
import { getUserTest, User, Session } from "../classes";
|
||||
import RessourcePanel from "./ressourcePanel";
|
||||
import { LocalDataContext } from "../context/LocalDataContext";
|
||||
|
||||
export default function TestApp() {
|
||||
const initialUser = getUserTest();
|
||||
initialUser.role = "Athlete"; // Change role here for testing
|
||||
const [user, setUser] = useState<User>(initialUser);
|
||||
const [sessions, setSessions] = useState<Session[]>(initialUser.sessions || []);
|
||||
const [users, setUsers] = useState<User[]>([initialUser]);
|
||||
|
||||
return (
|
||||
<LocalDataContext.Provider value={{ user, setUser, sessions, setSessions, users, setUsers }}>
|
||||
<h1>Test Utilisateur</h1>
|
||||
<div>Nom: {String(user.nom)}</div>
|
||||
<RessourcePanel />
|
||||
</LocalDataContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -149,7 +149,7 @@ export async function getSessionsAPI(): Promise<Session[]> {
|
||||
}
|
||||
export async function getUsersAPI(): Promise<User[]> {
|
||||
try {
|
||||
const response = await api.get<User[]>("/users");
|
||||
const response = await api.get<User[]>("/coach/all");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
|
||||
Reference in New Issue
Block a user