This commit is contained in:
Amaël Kesteman
2026-01-08 12:04:17 +01:00
6 changed files with 27 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ import java.util.List;
@Data
public class SessionDTO {
private Integer id;
private String name;
private Boolean isRecurrent;
private LocalDateTime creneau;

View File

@@ -46,7 +46,7 @@ public class ActiviteResource {
})
@PostMapping("/create")
@ResponseBody
@PreAuthorize("hasRole('Coach')")
@PreAuthorize("hasRole('coach')")
public ResponseEntity<String> create(@RequestBody ActiviteDTO dto) {
try {
@@ -69,7 +69,7 @@ public class ActiviteResource {
})
@DeleteMapping("/delete/{id}")
@ResponseBody
@PreAuthorize("hasRole('Coach')")
@PreAuthorize("hasRole('coach')")
public ResponseEntity<String> 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<String> 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<ActiviteDTO> 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<List<ActiviteDTO>> 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<List<ActiviteDTO>> getActivityByTheme(@PathVariable("theme") String theme) {
try {

View File

@@ -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<AthleteDTO> 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<List<AthleteDTO>> all() {
List<Athlete> athletes = athleteDAO.findAll();
List<AthleteDTO> 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<AthleteDTO> 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<AthleteDTO> 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<Void> 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;
}

View File

@@ -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<List<SessionDTO>> getAll() {
List<Session> sessions = sessionDAO.findAll();
List<SessionDTO> 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<String> 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<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
HttpStatus.NOT_FOUND, "Session not found with id " + id));

View File

@@ -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;
}

View File

@@ -51,7 +51,7 @@ export const Login =() =>{
email: tokenParsed?.email,
nom: tokenParsed?.family_name,
prenom: tokenParsed?.given_name,
role: "Athlete",
role: "athlete",
sessions: []
});
}