Changed roles in Activite and Session endpoints
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 {
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user