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