From 988a7c16b353439b6101597c49c84866dbbf836c Mon Sep 17 00:00:00 2001 From: Alexis Leboeuf Date: Thu, 8 Jan 2026 12:01:56 +0100 Subject: [PATCH] P U S H --- .../hackathon/FrisbYEE/rest/AthleteResource.java | 15 +++++++++------ front_end/src/classes.tsx | 10 +++++----- front_end/src/components/login.tsx | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java index 56c46d3..cc9112e 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/AthleteResource.java @@ -10,6 +10,7 @@ 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.CrossOrigin; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import hackathon.FrisbYEE.jpa.dto.ActiviteDTO; import hackathon.FrisbYEE.jpa.dto.AthleteDTO; import hackathon.FrisbYEE.jpa.dto.SessionDTO; @@ -45,7 +48,7 @@ public class AthleteResource { @ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class))) }) @PostMapping("/create") - @PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('Athlete')") public ResponseEntity create(@RequestBody AthleteDTO dto) { Athlete athlete = mapToEntity(dto); athleteDAO.save(athlete); @@ -57,7 +60,7 @@ public class AthleteResource { @ApiResponse(responseCode = "200", description = "Récupère tous les athlètes", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class))) }) @GetMapping("/all") - @PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')") public ResponseEntity> all() { List athletes = athleteDAO.findAll(); List dtos = new ArrayList<>(); @@ -72,7 +75,7 @@ public class AthleteResource { @ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class))) }) @GetMapping("/{id}") - @PreAuthorize("hasRole('Admin') or hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')") public ResponseEntity getById(@PathVariable Integer id) { return athleteDAO.findById(id) .map(athlete -> ResponseEntity.ok(mapToDTO(athlete))) @@ -84,7 +87,7 @@ public class AthleteResource { @ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class))) }) @PutMapping("/{id}") - @PreAuthorize("hasRole('ADMIN') or #id == principal.id") + @PreAuthorize("hasRole('admin') or #id == principal.id") public ResponseEntity update(@PathVariable Integer id, @RequestBody AthleteDTO dto) { try { Athlete athlete = athleteDAO.findById(id).get(); @@ -115,7 +118,7 @@ public class AthleteResource { @ApiResponse(responseCode = "200", description = "Suppression effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class))) }) @DeleteMapping("/{id}") - @PreAuthorize("hasRole('Admin')") + @PreAuthorize("hasRole('admin')") public ResponseEntity delete(@PathVariable Integer id) { if (!athleteDAO.existsById(id)) { return ResponseEntity.notFound().build(); @@ -141,7 +144,7 @@ public class AthleteResource { athlete.setKeycloakId(dto.getId_keycloak()); athlete.setCategorie(dto.getCategorie()); athlete.setNiveau(dto.getNiveau()); - athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.ATHLETE); + athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete); return athlete; } diff --git a/front_end/src/classes.tsx b/front_end/src/classes.tsx index 011a8fc..c20a6fc 100644 --- a/front_end/src/classes.tsx +++ b/front_end/src/classes.tsx @@ -1,5 +1,5 @@ export type Groupe = "Entrainement" | "Competition" | "Loisir"| ""; -export type Role = "Admin" | "Athlete" | "Coach"; +export type Role = "admin" | "athlete" | "coach"; export class User{ id!: number; @@ -98,7 +98,7 @@ export function getUserTest():User{ user.id = 0; user.nom = "Emilien-Yee NootNoot"; - user.role = "Coach" + user.role = "coach" s1.creneau = new Date(); s1.id = 1; s1.name = "Entrainement Frisbee" @@ -185,9 +185,9 @@ export function getUserTest():User{ user.sessions.push(s2); user.sessions.push(s3); - athlete1.role = "Athlete"; - athlete2.role = "Athlete"; - athlete3.role = "Athlete"; + athlete1.role = "athlete"; + athlete2.role = "athlete"; + athlete3.role = "athlete"; return user; } diff --git a/front_end/src/components/login.tsx b/front_end/src/components/login.tsx index 0abca28..a917c32 100644 --- a/front_end/src/components/login.tsx +++ b/front_end/src/components/login.tsx @@ -51,7 +51,7 @@ export const Login =() =>{ email: tokenParsed?.email, nom: tokenParsed?.family_name, prenom: tokenParsed?.given_name, - role: "Athlete", + role: "athlete", sessions: [] }); }