@Test public void update() throws Exception { mockMvc.perform(MockMvcRequestBuilders.put("/user/update") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(requestJson) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()); }
@RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors) throws Exception { user.setUpdate_user_no(currentUser.getUserNo()); ValidateResult validateRes = userService.validatePermision(currentUser, errors) .addAssert(() -> loginUserDao.getUserById(user.getId()) != null, message.user_add_fail_not_exist) .addAssert(() -> userService.canUpdateOrDeleteUser(currentUser, user), message.permisson_user_crud) .addAssert(() -> userService.update(user), message.db_message_update_operation_failed).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); }
UserController { @RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors) throws Exception { user.setUpdate_user_no(currentUser.getUserNo()); ValidateResult validateRes = userService.validatePermision(currentUser, errors) .addAssert(() -> loginUserDao.getUserById(user.getId()) != null, message.user_add_fail_not_exist) .addAssert(() -> userService.canUpdateOrDeleteUser(currentUser, user), message.permisson_user_crud) .addAssert(() -> userService.update(user), message.db_message_update_operation_failed).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); } }
UserController { @RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors) throws Exception { user.setUpdate_user_no(currentUser.getUserNo()); ValidateResult validateRes = userService.validatePermision(currentUser, errors) .addAssert(() -> loginUserDao.getUserById(user.getId()) != null, message.user_add_fail_not_exist) .addAssert(() -> userService.canUpdateOrDeleteUser(currentUser, user), message.permisson_user_crud) .addAssert(() -> userService.update(user), message.db_message_update_operation_failed).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); }  }
UserController { @RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors) throws Exception { user.setUpdate_user_no(currentUser.getUserNo()); ValidateResult validateRes = userService.validatePermision(currentUser, errors) .addAssert(() -> loginUserDao.getUserById(user.getId()) != null, message.user_add_fail_not_exist) .addAssert(() -> userService.canUpdateOrDeleteUser(currentUser, user), message.permisson_user_crud) .addAssert(() -> userService.update(user), message.db_message_update_operation_failed).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); }  @RequestMapping(value = "/group/users") ServiceResult<List<LoginUser>> findGroupUserList(@RequestParam(value = "groupId", defaultValue = "0") Long groupId); @RequestMapping(value = "/list", method = RequestMethod.POST) ServiceResult<ListResult<LoginUserView>> findUserPageList(@RequestBody Paging<LoginUser> paging); @RequestMapping(value = "/getWorkInfo") ServiceResult<LoginUser> getWorkInfo(@RequestParam(value = "name", defaultValue = "") String name, @CurrentUser LoginUser user); @RequestMapping(value = "/add", method = RequestMethod.POST) ServiceResult<String> addUser(@Validated(AddUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping(value = "/update", method = RequestMethod.PUT) ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping(value = "/delete", method = RequestMethod.DELETE) ServiceResult<String> delete(@Validated(DeleteUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping("/buttons") ServiceResult getDataBaseButton(@CurrentUser LoginUser user); }
UserController { @RequestMapping(value = "/update", method = RequestMethod.PUT) public ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors) throws Exception { user.setUpdate_user_no(currentUser.getUserNo()); ValidateResult validateRes = userService.validatePermision(currentUser, errors) .addAssert(() -> loginUserDao.getUserById(user.getId()) != null, message.user_add_fail_not_exist) .addAssert(() -> userService.canUpdateOrDeleteUser(currentUser, user), message.permisson_user_crud) .addAssert(() -> userService.update(user), message.db_message_update_operation_failed).validate(); if (!validateRes.isValid()) { return ServiceResult.fail(validateRes.getSummarize()); } return ServiceResult.success(); }  @RequestMapping(value = "/group/users") ServiceResult<List<LoginUser>> findGroupUserList(@RequestParam(value = "groupId", defaultValue = "0") Long groupId); @RequestMapping(value = "/list", method = RequestMethod.POST) ServiceResult<ListResult<LoginUserView>> findUserPageList(@RequestBody Paging<LoginUser> paging); @RequestMapping(value = "/getWorkInfo") ServiceResult<LoginUser> getWorkInfo(@RequestParam(value = "name", defaultValue = "") String name, @CurrentUser LoginUser user); @RequestMapping(value = "/add", method = RequestMethod.POST) ServiceResult<String> addUser(@Validated(AddUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping(value = "/update", method = RequestMethod.PUT) ServiceResult<String> update(@Validated(UpdateUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping(value = "/delete", method = RequestMethod.DELETE) ServiceResult<String> delete(@Validated(DeleteUser.class) @RequestBody LoginUser user, @CurrentUser LoginUser currentUser, Errors errors); @RequestMapping("/buttons") ServiceResult getDataBaseButton(@CurrentUser LoginUser user);  }