diff --git a/back_end/src/main/java/hackathon/FrisbYEE/jpa/dto/SessionDTO.java b/back_end/src/main/java/hackathon/FrisbYEE/jpa/dto/SessionDTO.java index 2e44668..3993af5 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/jpa/dto/SessionDTO.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/jpa/dto/SessionDTO.java @@ -7,7 +7,7 @@ import java.util.List; @Data public class SessionDTO { - + private Integer id; private String name; private Boolean isRecurrent; private LocalDateTime creneau; diff --git a/back_end/src/main/java/hackathon/FrisbYEE/rest/ActiviteResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/ActiviteResource.java index 27bf285..2698ff9 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/ActiviteResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/ActiviteResource.java @@ -46,7 +46,7 @@ public class ActiviteResource { }) @PostMapping("/create") @ResponseBody - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity create(@RequestBody ActiviteDTO dto) { try { @@ -69,7 +69,7 @@ public class ActiviteResource { }) @DeleteMapping("/delete/{id}") @ResponseBody - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity delete(@PathVariable("id") int id) { try { Activite activite = activiteDAO.findById(id).get(); @@ -89,7 +89,7 @@ public class ActiviteResource { }) @PostMapping("/update/{id}") @ResponseBody - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity modifyById(@PathVariable("id") int id, @RequestBody ActiviteDTO dto) { try { Session session = sessionDAO.findById(dto.getSessionId()).get(); @@ -114,7 +114,7 @@ public class ActiviteResource { schema = @Schema(implementation = ActiviteDTO.class))) }) @GetMapping("/{id}") - @PreAuthorize("hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") @ResponseBody public ResponseEntity getActivityById(@PathVariable("id") int id) { try { @@ -133,7 +133,7 @@ public class ActiviteResource { schema = @Schema(implementation = ActiviteDTO.class))) }) @GetMapping("/all") - @PreAuthorize("hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") @ResponseBody public ResponseEntity> getAllActivity() { try { @@ -153,7 +153,7 @@ public class ActiviteResource { schema = @Schema(implementation = ActiviteDTO.class))) }) @GetMapping("/theme/{theme}") - @PreAuthorize("hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") @ResponseBody public ResponseEntity> getActivityByTheme(@PathVariable("theme") String theme) { try { 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/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java index b620d73..8269ec5 100644 --- a/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java +++ b/back_end/src/main/java/hackathon/FrisbYEE/rest/SessionResource.java @@ -40,7 +40,7 @@ public class SessionResource { @PostMapping("/create") @ResponseBody - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity create(@RequestBody SessionDTO dto) { try { Session session = maptoEntity(dto); @@ -53,7 +53,7 @@ public class SessionResource { } @GetMapping("/all") - @PreAuthorize("hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") public ResponseEntity> getAll() { List sessions = sessionDAO.findAll(); List dtos = new ArrayList<>(); @@ -64,7 +64,7 @@ public class SessionResource { } @GetMapping("/{id}") - @PreAuthorize("hasRole('Coach') or hasRole('Athlete')") + @PreAuthorize("hasRole('coach') or hasRole('athlete')") public ResponseEntity getById(@PathVariable Integer id) { try { Session session = sessionDAO.findById(id).orElseThrow(); @@ -76,7 +76,7 @@ public class SessionResource { @DeleteMapping("/delete/{id}") @ResponseBody - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity delete(@PathVariable("id") int id) { try { Session session = sessionDAO.findById(id).get(); @@ -88,7 +88,7 @@ public class SessionResource { } @PutMapping("/update/{id}") - @PreAuthorize("hasRole('Coach')") + @PreAuthorize("hasRole('coach')") public ResponseEntity updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) { Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException( HttpStatus.NOT_FOUND, "Session not found with id " + id)); diff --git a/front_end/src/classes.tsx b/front_end/src/classes.tsx index 9639d09..cbea7ec 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: [] }); }