Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/hackathon
This commit is contained in:
@@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class SessionDTO {
|
public class SessionDTO {
|
||||||
|
private Integer id;
|
||||||
private String name;
|
private String name;
|
||||||
private Boolean isRecurrent;
|
private Boolean isRecurrent;
|
||||||
private LocalDateTime creneau;
|
private LocalDateTime creneau;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class ActiviteResource {
|
|||||||
})
|
})
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<String> create(@RequestBody ActiviteDTO dto) {
|
public ResponseEntity<String> create(@RequestBody ActiviteDTO dto) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -69,7 +69,7 @@ public class ActiviteResource {
|
|||||||
})
|
})
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<String> delete(@PathVariable("id") int id) {
|
public ResponseEntity<String> delete(@PathVariable("id") int id) {
|
||||||
try {
|
try {
|
||||||
Activite activite = activiteDAO.findById(id).get();
|
Activite activite = activiteDAO.findById(id).get();
|
||||||
@@ -89,7 +89,7 @@ public class ActiviteResource {
|
|||||||
})
|
})
|
||||||
@PostMapping("/update/{id}")
|
@PostMapping("/update/{id}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<String> modifyById(@PathVariable("id") int id, @RequestBody ActiviteDTO dto) {
|
public ResponseEntity<String> modifyById(@PathVariable("id") int id, @RequestBody ActiviteDTO dto) {
|
||||||
try {
|
try {
|
||||||
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
||||||
@@ -114,7 +114,7 @@ public class ActiviteResource {
|
|||||||
schema = @Schema(implementation = ActiviteDTO.class)))
|
schema = @Schema(implementation = ActiviteDTO.class)))
|
||||||
})
|
})
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@PreAuthorize("hasRole('Coach') or hasRole('Athlete')")
|
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<ActiviteDTO> getActivityById(@PathVariable("id") int id) {
|
public ResponseEntity<ActiviteDTO> getActivityById(@PathVariable("id") int id) {
|
||||||
try {
|
try {
|
||||||
@@ -133,7 +133,7 @@ public class ActiviteResource {
|
|||||||
schema = @Schema(implementation = ActiviteDTO.class)))
|
schema = @Schema(implementation = ActiviteDTO.class)))
|
||||||
})
|
})
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@PreAuthorize("hasRole('Coach') or hasRole('Athlete')")
|
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<List<ActiviteDTO>> getAllActivity() {
|
public ResponseEntity<List<ActiviteDTO>> getAllActivity() {
|
||||||
try {
|
try {
|
||||||
@@ -153,7 +153,7 @@ public class ActiviteResource {
|
|||||||
schema = @Schema(implementation = ActiviteDTO.class)))
|
schema = @Schema(implementation = ActiviteDTO.class)))
|
||||||
})
|
})
|
||||||
@GetMapping("/theme/{theme}")
|
@GetMapping("/theme/{theme}")
|
||||||
@PreAuthorize("hasRole('Coach') or hasRole('Athlete')")
|
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ResponseEntity<List<ActiviteDTO>> getActivityByTheme(@PathVariable("theme") String theme) {
|
public ResponseEntity<List<ActiviteDTO>> getActivityByTheme(@PathVariable("theme") String theme) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Controller;
|
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.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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.RequestBody;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
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.ActiviteDTO;
|
||||||
import hackathon.FrisbYEE.jpa.dto.AthleteDTO;
|
import hackathon.FrisbYEE.jpa.dto.AthleteDTO;
|
||||||
import hackathon.FrisbYEE.jpa.dto.SessionDTO;
|
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)))
|
@ApiResponse(responseCode = "200", description = "Renvoie l'athlète créé", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||||
})
|
})
|
||||||
@PostMapping("/create")
|
@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) {
|
public ResponseEntity<AthleteDTO> create(@RequestBody AthleteDTO dto) {
|
||||||
Athlete athlete = mapToEntity(dto);
|
Athlete athlete = mapToEntity(dto);
|
||||||
athleteDAO.save(athlete);
|
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)))
|
@ApiResponse(responseCode = "200", description = "Récupère tous les athlètes", content = @Content(mediaType = "application/json", schema = @Schema(implementation = List.class)))
|
||||||
})
|
})
|
||||||
@GetMapping("/all")
|
@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() {
|
public ResponseEntity<List<AthleteDTO>> all() {
|
||||||
List<Athlete> athletes = athleteDAO.findAll();
|
List<Athlete> athletes = athleteDAO.findAll();
|
||||||
List<AthleteDTO> dtos = new ArrayList<>();
|
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)))
|
@ApiResponse(responseCode = "200", description = "Récupération effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||||
})
|
})
|
||||||
@GetMapping("/{id}")
|
@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) {
|
public ResponseEntity<AthleteDTO> getById(@PathVariable Integer id) {
|
||||||
return athleteDAO.findById(id)
|
return athleteDAO.findById(id)
|
||||||
.map(athlete -> ResponseEntity.ok(mapToDTO(athlete)))
|
.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)))
|
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||||
})
|
})
|
||||||
@PutMapping("/{id}")
|
@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) {
|
public ResponseEntity<AthleteDTO> update(@PathVariable Integer id, @RequestBody AthleteDTO dto) {
|
||||||
try {
|
try {
|
||||||
Athlete athlete = athleteDAO.findById(id).get();
|
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)))
|
@ApiResponse(responseCode = "200", description = "Suppression effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||||
})
|
})
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@PreAuthorize("hasRole('Admin')")
|
@PreAuthorize("hasRole('admin')")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
||||||
if (!athleteDAO.existsById(id)) {
|
if (!athleteDAO.existsById(id)) {
|
||||||
return ResponseEntity.notFound().build();
|
return ResponseEntity.notFound().build();
|
||||||
@@ -141,7 +144,7 @@ public class AthleteResource {
|
|||||||
athlete.setKeycloakId(dto.getId_keycloak());
|
athlete.setKeycloakId(dto.getId_keycloak());
|
||||||
athlete.setCategorie(dto.getCategorie());
|
athlete.setCategorie(dto.getCategorie());
|
||||||
athlete.setNiveau(dto.getNiveau());
|
athlete.setNiveau(dto.getNiveau());
|
||||||
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.ATHLETE);
|
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
||||||
return athlete;
|
return athlete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class SessionResource {
|
|||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
public ResponseEntity<?> create(@RequestBody SessionDTO dto) {
|
||||||
try {
|
try {
|
||||||
Session session = maptoEntity(dto);
|
Session session = maptoEntity(dto);
|
||||||
@@ -53,7 +53,7 @@ public class SessionResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@PreAuthorize("hasRole('Coach') or hasRole('Athlete')")
|
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||||
public ResponseEntity<List<SessionDTO>> getAll() {
|
public ResponseEntity<List<SessionDTO>> getAll() {
|
||||||
List<Session> sessions = sessionDAO.findAll();
|
List<Session> sessions = sessionDAO.findAll();
|
||||||
List<SessionDTO> dtos = new ArrayList<>();
|
List<SessionDTO> dtos = new ArrayList<>();
|
||||||
@@ -64,7 +64,7 @@ public class SessionResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@PreAuthorize("hasRole('Coach') or hasRole('Athlete')")
|
@PreAuthorize("hasRole('coach') or hasRole('athlete')")
|
||||||
public ResponseEntity<?> getById(@PathVariable Integer id) {
|
public ResponseEntity<?> getById(@PathVariable Integer id) {
|
||||||
try {
|
try {
|
||||||
Session session = sessionDAO.findById(id).orElseThrow();
|
Session session = sessionDAO.findById(id).orElseThrow();
|
||||||
@@ -76,7 +76,7 @@ public class SessionResource {
|
|||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<String> delete(@PathVariable("id") int id) {
|
public ResponseEntity<String> delete(@PathVariable("id") int id) {
|
||||||
try {
|
try {
|
||||||
Session session = sessionDAO.findById(id).get();
|
Session session = sessionDAO.findById(id).get();
|
||||||
@@ -88,7 +88,7 @@ public class SessionResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('coach')")
|
||||||
public ResponseEntity<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {
|
public ResponseEntity<Void> updateSession(@PathVariable Integer id, @RequestBody SessionDTO dto) {
|
||||||
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
|
Session session = sessionDAO.findById(id).orElseThrow(() -> new ResponseStatusException(
|
||||||
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
HttpStatus.NOT_FOUND, "Session not found with id " + id));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
export type Groupe = "Entrainement" | "Competition" | "Loisir"| "";
|
||||||
export type Role = "Admin" | "Athlete" | "Coach";
|
export type Role = "admin" | "athlete" | "coach";
|
||||||
|
|
||||||
export class User{
|
export class User{
|
||||||
id!: number;
|
id!: number;
|
||||||
@@ -98,7 +98,7 @@ export function getUserTest():User{
|
|||||||
|
|
||||||
user.id = 0;
|
user.id = 0;
|
||||||
user.nom = "Emilien-Yee NootNoot";
|
user.nom = "Emilien-Yee NootNoot";
|
||||||
user.role = "Coach"
|
user.role = "coach"
|
||||||
s1.creneau = new Date();
|
s1.creneau = new Date();
|
||||||
s1.id = 1;
|
s1.id = 1;
|
||||||
s1.name = "Entrainement Frisbee"
|
s1.name = "Entrainement Frisbee"
|
||||||
@@ -185,9 +185,9 @@ export function getUserTest():User{
|
|||||||
user.sessions.push(s2);
|
user.sessions.push(s2);
|
||||||
user.sessions.push(s3);
|
user.sessions.push(s3);
|
||||||
|
|
||||||
athlete1.role = "Athlete";
|
athlete1.role = "athlete";
|
||||||
athlete2.role = "Athlete";
|
athlete2.role = "athlete";
|
||||||
athlete3.role = "Athlete";
|
athlete3.role = "athlete";
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export const Login =() =>{
|
|||||||
email: tokenParsed?.email,
|
email: tokenParsed?.email,
|
||||||
nom: tokenParsed?.family_name,
|
nom: tokenParsed?.family_name,
|
||||||
prenom: tokenParsed?.given_name,
|
prenom: tokenParsed?.given_name,
|
||||||
role: "Athlete",
|
role: "athlete",
|
||||||
sessions: []
|
sessions: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user