Compare commits
2 Commits
12846ed83d
...
017235cccf
Author | SHA1 | Date | |
---|---|---|---|
017235cccf | |||
1bff48a4b9 |
@ -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<>();
|
||||||
@ -81,4 +94,4 @@ public class InscriptionController {
|
|||||||
|
|
||||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,14 +3,14 @@
|
|||||||
*
|
*
|
||||||
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
|
* TODO: On time of writing, the backend doesn't support these endpoints so it could be modified in the future.
|
||||||
*/
|
*/
|
||||||
import { restGet } from './restConsumer.js'
|
import {restGet, restPatch} from './restConsumer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new register requests that can be recovered by the registering service
|
* create a new register requests that can be recovered by the registering service
|
||||||
* TODO: add info in the Object (I don't know what will be needed)
|
* TODO: add info in the Object (I don't know what will be needed)
|
||||||
*/
|
*/
|
||||||
export async function createRegister(){
|
export async function createRegister(){
|
||||||
return restPost("/requests/register"});
|
return restPost("/request/register"});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,12 +24,12 @@ export async function getRegisters(){
|
|||||||
* Get info on a particular registering request
|
* Get info on a particular registering request
|
||||||
*/
|
*/
|
||||||
export async function getRegisters(id){
|
export async function getRegisters(id){
|
||||||
return restGet("/requests/register/" + id);
|
return restGet("/request/register/" + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the state of a requests.
|
* Change the state of a requests.
|
||||||
*/
|
*/
|
||||||
export async function validateRegister(id, state){
|
export async function validateRegister(id, state){
|
||||||
return restPost("/requests/register/" + id, {state: state});
|
return restPatch("/request/register/" + id, {state: state});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user