From 800381c2905059881a3aa2ff38440619a8498670 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 09:45:28 +0800 Subject: [PATCH] 1.normalize swagger response, refer to this wiki: https://www.bmabk.com/index.php/post/135277.html --- .../luoo/user/controller/UserController.java | 8 ++++---- .../com/luoo/user/{vo => dto}/UserVO.java | 3 +-- .../luoo/user/dto/response/UserRespDTO.java | 19 +++++++++++++++++++ .../com/luoo/user/service/UserService.java | 10 +++++----- 4 files changed, 29 insertions(+), 11 deletions(-) rename luoo_user/src/main/java/com/luoo/user/{vo => dto}/UserVO.java (94%) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java index c879de6..9d29427 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java @@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.pojo.User; import com.luoo.user.service.UserService; -import com.luoo.user.vo.UserVO; import entity.PageResult; import entity.Result; @@ -89,14 +89,14 @@ public class UserController { if (!checkcodeRedis.equals(checkcode)) { return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码"); } - UserVO userVO=userService.loginOrRegister(mobile); + UserRespDTO userVO=userService.loginOrRegister(mobile); return ResultVO.success(userVO); } @ApiOperation(value="3.游客登录返回token",notes="token中的subject和roles均为tourist") @RequestMapping(value = "/touristLogin",method = RequestMethod.GET) - public ResultVO touristLogin(){ - UserVO userVO=userService.touristLogin(); + public ResultVO touristLogin(){ + UserRespDTO userVO=userService.touristLogin(); return ResultVO.success(userVO); } diff --git a/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java b/luoo_user/src/main/java/com/luoo/user/dto/UserVO.java similarity index 94% rename from luoo_user/src/main/java/com/luoo/user/vo/UserVO.java rename to luoo_user/src/main/java/com/luoo/user/dto/UserVO.java index e4b4c62..d5db134 100644 --- a/luoo_user/src/main/java/com/luoo/user/vo/UserVO.java +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserVO.java @@ -1,10 +1,9 @@ -package com.luoo.user.vo; +package com.luoo.user.dto; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @Data -@ApiModel(value = "用户") public class UserVO { @ApiModelProperty(value = "ID") private String id;//ID diff --git a/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java new file mode 100644 index 0000000..d21825b --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/response/UserRespDTO.java @@ -0,0 +1,19 @@ +package com.luoo.user.dto.response; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +@Data +public class UserRespDTO { + @ApiModelProperty(value = "ID") + private String id;//ID + @ApiModelProperty(value = "昵称,首次注册登录,登录用户随机为“雀乐XXX”,游客为“游客XXX”",example="雀乐XXX") + private String nickname;//昵称 + @ApiModelProperty(value = "性别,0为男,1 为女,首次注册登录,默认为0",example="0") + private String sex;//性别 + @ApiModelProperty(value = "头像,首次注册登录,默认头像",example="default") + private String avatar;//头像 + @ApiModelProperty(value = "个性签名,首次注册登录,默认为“无签名”",example="无签名") + private String personality;//个性 + @ApiModelProperty(value = "TOKEN") + private String token; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserService.java b/luoo_user/src/main/java/com/luoo/user/service/UserService.java index 9f2fa9d..8a08606 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserService.java @@ -33,9 +33,9 @@ import util.IdWorker; import com.apifan.common.random.RandomSource; import com.luoo.user.dao.UserDao; +import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.enumerate.Gender; import com.luoo.user.pojo.User; -import com.luoo.user.vo.UserVO; import util.JwtUtil; @@ -255,7 +255,7 @@ public class UserService { userDao.updatefanscount(x,friendid); userDao.updatefollowcount(x,userid); } - public UserVO loginOrRegister(String mobile) { + public UserRespDTO loginOrRegister(String mobile) { User user = userDao.findByMobile(mobile); if(null==user) { user=new User(); @@ -268,7 +268,7 @@ public class UserService { userDao.save(user); } - UserVO userVO=new UserVO(); + UserRespDTO userVO=new UserRespDTO(); BeanUtils.copyProperties(user, userVO); String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user"); userVO.setToken(token); @@ -280,8 +280,8 @@ public class UserService { } - public UserVO touristLogin() { - UserVO userVO=new UserVO(); + public UserRespDTO touristLogin() { + UserRespDTO userVO=new UserRespDTO(); userVO.setId(String.valueOf(idWorker.nextId())); userVO.setNickname("游客"+getRandomNickName()); userVO.setSex(Gender.Male.getCode());