fixed inscription in the backend
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m8s
Build and test backend / Test-backend (pull_request) Successful in 2m0s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s

This commit is contained in:
Bartha Maxime 2024-03-15 17:29:45 +01:00
parent 1bff48a4b9
commit 017235cccf
3 changed files with 28 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService; import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.InscriptionService; import ovh.herisson.Clyde.Services.InscriptionService;
import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.RequestState;
import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User; import ovh.herisson.Clyde.Tables.User;
import java.util.ArrayList; import java.util.ArrayList;
@ -28,7 +29,7 @@ public class InscriptionController {
} }
@GetMapping("/inscriptionRequests") @GetMapping("/requests/register")
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){ public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);} if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
@ -44,17 +45,29 @@ public class InscriptionController {
} }
@GetMapping("/inscriptionRequest/{id}") @GetMapping("/request/register/{id}")
public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){ public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){
InscriptionRequest inscriptionRequest = inscriptionServ.getById(id); InscriptionRequest inscriptionRequest = inscriptionServ.getById(id);
if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);} if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);}
return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK); return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK);
} }
@GetMapping("request/user/{id}")
public ResponseEntity<InscriptionRequest> 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<InscriptionRequest> 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<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) { private Map<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
Map<String, Object> toReturn = new HashMap<>(); Map<String, Object> toReturn = new HashMap<>();

View File

@ -44,11 +44,9 @@ public class LoginController {
return ResponseEntity.ok().headers(responseHeaders).build(); return ResponseEntity.ok().headers(responseHeaders).build();
} }
@PostMapping("/register") @PostMapping("/request/register")
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){ public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
authServ.register(inscriptionRequest); authServ.register(inscriptionRequest);
return new ResponseEntity<>("Is OK", HttpStatus.OK); return new ResponseEntity<>("Is OK", HttpStatus.OK);
} }
} }

View File

@ -3,6 +3,7 @@ package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.InscriptionRepository; import ovh.herisson.Clyde.Repositories.InscriptionRepository;
import ovh.herisson.Clyde.Tables.InscriptionRequest; import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.RequestState;
@Service @Service
public class InscriptionService { public class InscriptionService {
@ -24,4 +25,10 @@ public class InscriptionService {
public Iterable<InscriptionRequest> getAll(){ public Iterable<InscriptionRequest> getAll(){
return inscriptionRepo.findAll(); return inscriptionRepo.findAll();
} }
public void modifyState(long id, RequestState requestState) {
InscriptionRequest inscriptionRequest = getById(id);
inscriptionRequest.setState(requestState);
save(inscriptionRequest);
}
} }