1.normalize swagger response, refer to this wiki: https://www.bmabk.com/index.php/post/135277.html

main
Gary 11 months ago
parent e8b51b82f9
commit 800381c290

@ -14,9 +14,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.User; import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService; import com.luoo.user.service.UserService;
import com.luoo.user.vo.UserVO;
import entity.PageResult; import entity.PageResult;
import entity.Result; import entity.Result;
@ -89,14 +89,14 @@ public class UserController {
if (!checkcodeRedis.equals(checkcode)) { if (!checkcodeRedis.equals(checkcode)) {
return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码"); return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码");
} }
UserVO userVO=userService.loginOrRegister(mobile); UserRespDTO userVO=userService.loginOrRegister(mobile);
return ResultVO.success(userVO); return ResultVO.success(userVO);
} }
@ApiOperation(value="3.游客登录返回token",notes="token中的subject和roles均为tourist") @ApiOperation(value="3.游客登录返回token",notes="token中的subject和roles均为tourist")
@RequestMapping(value = "/touristLogin",method = RequestMethod.GET) @RequestMapping(value = "/touristLogin",method = RequestMethod.GET)
public ResultVO<UserVO> touristLogin(){ public ResultVO<UserRespDTO> touristLogin(){
UserVO userVO=userService.touristLogin(); UserRespDTO userVO=userService.touristLogin();
return ResultVO.success(userVO); return ResultVO.success(userVO);
} }

@ -1,10 +1,9 @@
package com.luoo.user.vo; package com.luoo.user.dto;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
@Data @Data
@ApiModel(value = "用户")
public class UserVO { public class UserVO {
@ApiModelProperty(value = "ID") @ApiModelProperty(value = "ID")
private String id;//ID private String id;//ID

@ -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;
}

@ -33,9 +33,9 @@ import util.IdWorker;
import com.apifan.common.random.RandomSource; import com.apifan.common.random.RandomSource;
import com.luoo.user.dao.UserDao; import com.luoo.user.dao.UserDao;
import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.enumerate.Gender; import com.luoo.user.enumerate.Gender;
import com.luoo.user.pojo.User; import com.luoo.user.pojo.User;
import com.luoo.user.vo.UserVO;
import util.JwtUtil; import util.JwtUtil;
@ -255,7 +255,7 @@ public class UserService {
userDao.updatefanscount(x,friendid); userDao.updatefanscount(x,friendid);
userDao.updatefollowcount(x,userid); userDao.updatefollowcount(x,userid);
} }
public UserVO loginOrRegister(String mobile) { public UserRespDTO loginOrRegister(String mobile) {
User user = userDao.findByMobile(mobile); User user = userDao.findByMobile(mobile);
if(null==user) { if(null==user) {
user=new User(); user=new User();
@ -268,7 +268,7 @@ public class UserService {
userDao.save(user); userDao.save(user);
} }
UserVO userVO=new UserVO(); UserRespDTO userVO=new UserRespDTO();
BeanUtils.copyProperties(user, userVO); BeanUtils.copyProperties(user, userVO);
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user"); String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user");
userVO.setToken(token); userVO.setToken(token);
@ -280,8 +280,8 @@ public class UserService {
} }
public UserVO touristLogin() { public UserRespDTO touristLogin() {
UserVO userVO=new UserVO(); UserRespDTO userVO=new UserRespDTO();
userVO.setId(String.valueOf(idWorker.nextId())); userVO.setId(String.valueOf(idWorker.nextId()));
userVO.setNickname("游客"+getRandomNickName()); userVO.setNickname("游客"+getRandomNickName());
userVO.setSex(Gender.Male.getCode()); userVO.setSex(Gender.Male.getCode());

Loading…
Cancel
Save