diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java index a997c54..7757242 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/InscriptionController.java @@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse; import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.InscriptionService; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.User; import java.util.ArrayList; @@ -28,7 +29,7 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequests") + @GetMapping("/requests/register") public ResponseEntity>> getAllRequests(@RequestHeader("Authorization") String token){ if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} @@ -44,17 +45,29 @@ public class InscriptionController { } - @GetMapping("/inscriptionRequest/{id}") + @GetMapping("/request/register/{id}") public ResponseEntity> getById(@PathVariable long id){ - - - InscriptionRequest inscriptionRequest = inscriptionServ.getById(id); if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);} return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK); } + @GetMapping("request/user/{id}") + public ResponseEntity getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){ + //todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat) + return null; + } + + @PatchMapping("/request/register/{id}") + public ResponseEntity changeRequestState(@PathVariable long id, + @RequestHeader("Authorize") String token, + @RequestBody RequestState requestState) + { + if (!isSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null); + inscriptionServ.modifyState(id, requestState); + return null; + } private Map requestWithoutPassword(InscriptionRequest inscriptionRequest) { Map toReturn = new HashMap<>(); @@ -81,4 +94,4 @@ public class InscriptionController { return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin; } -} +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java index bc6222e..a47603b 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/LoginController.java @@ -44,11 +44,9 @@ public class LoginController { return ResponseEntity.ok().headers(responseHeaders).build(); } - @PostMapping("/register") + @PostMapping("/request/register") public ResponseEntity register(@RequestBody InscriptionRequest inscriptionRequest){ authServ.register(inscriptionRequest); return new ResponseEntity<>("Is OK", HttpStatus.OK); } -} - - +} \ No newline at end of file diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 4b2f6f4..f1bd092 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services; import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Tables.InscriptionRequest; +import ovh.herisson.Clyde.Tables.RequestState; @Service public class InscriptionService { @@ -24,4 +25,10 @@ public class InscriptionService { public Iterable getAll(){ return inscriptionRepo.findAll(); } + + public void modifyState(long id, RequestState requestState) { + InscriptionRequest inscriptionRequest = getById(id); + inscriptionRequest.setState(requestState); + save(inscriptionRequest); + } } \ No newline at end of file