Improved user state changing
This commit is contained in:
parent
b37e4bce34
commit
d3390792a1
@ -68,8 +68,8 @@ public class EmployeeController {
|
|||||||
return employeeService.deleteEmployee(login);
|
return employeeService.deleteEmployee(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PatchMapping("/{login}/{state}")
|
@PatchMapping("/{login}/change_state")
|
||||||
@Operation(description = "Enable/Disable user's ability to use QR code entrance. (ADMIN only) States: active / blocked", summary = "Enable/Disable QR")
|
@Operation(description = "Enable/Disable user's ability to use QR code entrance. (ADMIN only)", summary = "Enable/Disable QR")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "Modification Successful"),
|
@ApiResponse(responseCode = "200", description = "Modification Successful"),
|
||||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||||
@ -77,8 +77,8 @@ public class EmployeeController {
|
|||||||
@ApiResponse(responseCode = "404", description = "User not found"),
|
@ApiResponse(responseCode = "404", description = "User not found"),
|
||||||
@ApiResponse(responseCode = "400", description = "State doesn't exist"),
|
@ApiResponse(responseCode = "400", description = "State doesn't exist"),
|
||||||
})
|
})
|
||||||
public ResponseEntity<HttpStatusCode> changeState(@PathVariable String login, @PathVariable String state) {
|
public ResponseEntity<HttpStatusCode> changeState(@PathVariable String login) {
|
||||||
return employeeService.changeState(login, state);
|
return employeeService.changeState(login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
|
@ -13,7 +13,7 @@ public interface EmployeeService {
|
|||||||
ResponseEntity<EmployeeDTO> getUserInfo(Authentication auth);
|
ResponseEntity<EmployeeDTO> getUserInfo(Authentication auth);
|
||||||
ResponseEntity<Object> openTheDoor(Long code, Authentication auth);
|
ResponseEntity<Object> openTheDoor(Long code, Authentication auth);
|
||||||
ResponseEntity<HttpStatusCode> deleteEmployee(String login);
|
ResponseEntity<HttpStatusCode> deleteEmployee(String login);
|
||||||
ResponseEntity<HttpStatusCode> changeState(String login, String state);
|
ResponseEntity<HttpStatusCode> changeState(String login);
|
||||||
ResponseEntity<Page<EmployeeDTO>> getAllEmployees(Pageable pageable);
|
ResponseEntity<Page<EmployeeDTO>> getAllEmployees(Pageable pageable);
|
||||||
ResponseEntity<EmployeeDTO> getEmployeeByLogin(String login);
|
ResponseEntity<EmployeeDTO> getEmployeeByLogin(String login);
|
||||||
ResponseEntity<EmployeeDTO> updateEmployee(EmployeeDTO updateDTO, String login);
|
ResponseEntity<EmployeeDTO> updateEmployee(EmployeeDTO updateDTO, String login);
|
||||||
|
@ -86,26 +86,16 @@ public class EmployeeServiceImpl implements EmployeeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<HttpStatusCode> changeState(String login, String state) {
|
public ResponseEntity<HttpStatusCode> changeState(String login) {
|
||||||
Employee e = employeeRepository.findByLogin(login);
|
Employee e = employeeRepository.findByLogin(login);
|
||||||
if(e != null) {
|
if(e != null) {
|
||||||
if (Objects.equals(e.getAuthorities().iterator().next().getAuthority(), "ADMIN")) {
|
if (Objects.equals(e.getAuthorities().iterator().next().getAuthority(), "ADMIN")) {
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(state.equals("active")) {
|
e.setIsQREnabled(!e.getIsQREnabled());
|
||||||
e.setIsQREnabled(true);
|
employeeRepository.save(e);
|
||||||
employeeRepository.save(e);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
else if(state.equals("blocked")) {
|
|
||||||
e.setIsQREnabled(false);
|
|
||||||
employeeRepository.save(e);
|
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user