@Test public void getInformation() throws Exception { GroupDO root = GroupDO.builder().name("少林足球1111111").info("致敬周星星1111111").build(); GroupDO group = GroupDO.builder().name("少林足球").info("致敬周星星").build(); groupMapper.insert(root); groupMapper.insert(group); RegisterDTO dto = new RegisterDTO(); dto.setGroupIds(Arrays.asList(group.getId())); dto.setEmail(email); dto.setConfirmPassword(password); dto.setPassword(password); dto.setUsername(username); userService.createUser(dto); UserDO user = userService.getUserByUsername(username); LocalUser.setLocalUser(user); mvc.perform(MockMvcRequestBuilders.get("/cms/user/information") .contentType(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) .andExpect(MockMvcResultMatchers.jsonPath("$.username").value(username)) .andExpect(MockMvcResultMatchers.jsonPath("$.email").value(email)) .andExpect(MockMvcResultMatchers.jsonPath("$.groups").isArray()); }
@LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") public UserInfoVO getInformation() { UserDO user = LocalUser.getLocalUser(); List<GroupDO> groups = groupService.getUserGroupsByUserId(user.getId()); return new UserInfoVO(user, groups); }
UserController { @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") public UserInfoVO getInformation() { UserDO user = LocalUser.getLocalUser(); List<GroupDO> groups = groupService.getUserGroupsByUserId(user.getId()); return new UserInfoVO(user, groups); } }
UserController { @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") public UserInfoVO getInformation() { UserDO user = LocalUser.getLocalUser(); List<GroupDO> groups = groupService.getUserGroupsByUserId(user.getId()); return new UserInfoVO(user, groups); }  }
UserController { @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") public UserInfoVO getInformation() { UserDO user = LocalUser.getLocalUser(); List<GroupDO> groups = groupService.getUserGroupsByUserId(user.getId()); return new UserInfoVO(user, groups); }  @PostMapping("/register") @AdminRequired UnifyResponseVO<String> register(@RequestBody @Validated RegisterDTO validator); @PostMapping("/login") Tokens login(@RequestBody @Validated LoginDTO validator); @PutMapping @LoginRequired UnifyResponseVO update(@RequestBody @Validated UpdateInfoDTO validator); @PutMapping("/change_password") @LoginRequired UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator); @GetMapping("/refresh") @RefreshRequired Tokens refreshToken(); @GetMapping("/permissions") @LoginRequired @RouteMeta(permission = "查询自己拥有的权限", module = "用户", mount = true) UserPermissionsVO getPermissions(); @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") UserInfoVO getInformation(); }
UserController { @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") public UserInfoVO getInformation() { UserDO user = LocalUser.getLocalUser(); List<GroupDO> groups = groupService.getUserGroupsByUserId(user.getId()); return new UserInfoVO(user, groups); }  @PostMapping("/register") @AdminRequired UnifyResponseVO<String> register(@RequestBody @Validated RegisterDTO validator); @PostMapping("/login") Tokens login(@RequestBody @Validated LoginDTO validator); @PutMapping @LoginRequired UnifyResponseVO update(@RequestBody @Validated UpdateInfoDTO validator); @PutMapping("/change_password") @LoginRequired UnifyResponseVO updatePassword(@RequestBody @Validated ChangePasswordDTO validator); @GetMapping("/refresh") @RefreshRequired Tokens refreshToken(); @GetMapping("/permissions") @LoginRequired @RouteMeta(permission = "查询自己拥有的权限", module = "用户", mount = true) UserPermissionsVO getPermissions(); @LoginRequired @RouteMeta(permission = "查询自己信息", module = "用户", mount = true) @GetMapping("/information") UserInfoVO getInformation();  }