P U S H
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export const Login =() =>{
|
||||
email: tokenParsed?.email,
|
||||
nom: tokenParsed?.family_name,
|
||||
prenom: tokenParsed?.given_name,
|
||||
role: "Athlete",
|
||||
role: "athlete",
|
||||
sessions: []
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user