Max/Backend/Curriculum #106
@ -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<Iterable<Map<String,Object>>> 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<Map<String,Object>> 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<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) {
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
@ -81,4 +94,4 @@ public class InscriptionController {
|
||||
|
||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||
}
|
||||
}
|
||||
}
|
@ -44,11 +44,9 @@ public class LoginController {
|
||||
return ResponseEntity.ok().headers(responseHeaders).build();
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
@PostMapping("/request/register")
|
||||
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
|
||||
authServ.register(inscriptionRequest);
|
||||
return new ResponseEntity<>("Is OK", HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<InscriptionRequest> getAll(){
|
||||
return inscriptionRepo.findAll();
|
||||
}
|
||||
|
||||
public void modifyState(long id, RequestState requestState) {
|
||||
InscriptionRequest inscriptionRequest = getById(id);
|
||||
inscriptionRequest.setState(requestState);
|
||||
save(inscriptionRequest);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user