@Test(expected = IdeaLabApiException.class) public void userUpdate_NotValidRole() { EmployeeUpdateRequest request = new EmployeeUpdateRequest(); request.setUsername("username"); request.setRole("NOT_VALID"); GenericResponse response = operations.updateUser(request); }
public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; }
UserOperations { public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } }
UserOperations { public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } UserOperations(EmployeeRepo employeeRepo, BCryptPasswordEncoder encoder); }
UserOperations { public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } UserOperations(EmployeeRepo employeeRepo, BCryptPasswordEncoder encoder); DataResponse<BasicEmployee> getAllUsers(); GenericResponse userSignUp(EmployeeSignUpRequest request); GenericResponse deleteUser(Integer id); GenericResponse changePassword(UserChangePasswordRequest request); GenericResponse updateUser(EmployeeUpdateRequest request); }
UserOperations { public GenericResponse updateUser(EmployeeUpdateRequest request) { request.validate(); GenericResponse response = new GenericResponse(); Employee e = employeeRepo.findEmployeeByUsername(request.getUsername()); if(e == null){ throw new IdeaLabApiException(USER_NOT_FOUND); } String requestRole = request.getRole(); e.setRole(EmployeeRole.fromValue(requestRole)); employeeRepo.save(e); response.setSuccess(true); response.setMessage("Employee role updated successfully"); response.setHttpStatus(HttpStatus.ACCEPTED); return response; } UserOperations(EmployeeRepo employeeRepo, BCryptPasswordEncoder encoder); DataResponse<BasicEmployee> getAllUsers(); GenericResponse userSignUp(EmployeeSignUpRequest request); GenericResponse deleteUser(Integer id); GenericResponse changePassword(UserChangePasswordRequest request); GenericResponse updateUser(EmployeeUpdateRequest request);  }