From e84548fd1b87f58174c549723a6c378f6e2bc006 Mon Sep 17 00:00:00 2001 From: Gary Date: Thu, 7 Mar 2024 02:36:48 +0800 Subject: [PATCH] 1.move posted required attribute to request dto --- .../luoo/user/controller/LoginController.java | 28 ++++++--------- .../luoo/user/dto/request/FeedbackReq.java | 33 ++++++++++++++++++ .../com/luoo/user/dto/request/LoginReq.java | 34 +++++++++++++++++++ .../user/dto/request/TokenRefreshReq.java | 25 ++++++++++++++ 4 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/request/FeedbackReq.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/request/TokenRefreshReq.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index 4c14efa..0295bc6 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -18,7 +18,9 @@ import org.springframework.web.bind.annotation.*; import constants.Constants; import controller.BaseController; +import com.luoo.user.dto.request.LoginReq; import com.luoo.user.dto.request.SendSmsReq; +import com.luoo.user.dto.request.TokenRefreshReq; import com.luoo.user.dto.response.CountryCodeDTO; import com.luoo.user.dto.response.CreateImageCode; import com.luoo.user.pojo.UserInfo; @@ -95,31 +97,24 @@ public class LoginController extends BaseController { } @ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization") - @ApiImplicitParams({ @ApiImplicitParam(name = "mobile", value = "手机号", required = true), - @ApiImplicitParam(name = "mobileCheckCode", value = "6位验证码", required = true), - @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), - @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) @PostMapping("/appLogin") @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12) public Result appLogin(HttpServletRequest request, - @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) @RequestParam("mobile") String mobile, - @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) @RequestParam("mobileCheckCode") String mobileCheckCode, - @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam("deviceBrand") String deviceBrand) { + @VerifyParam LoginReq loginReq) { // 得到缓存中的验证码 - String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + deviceId; + String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId(); try { String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey); if (StringTools.isEmpty(redisMobileCheckCode)) { return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED); } - if (!redisMobileCheckCode.equals(mobileCheckCode)) { + if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) { return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); } UserInfo loginUserInfo = new UserInfo(); - loginUserInfo.setMobile(mobile); - loginUserInfo.setLastUseDeviceId(deviceId); - loginUserInfo.setLastUseDeviceBrand(deviceBrand); + loginUserInfo.setMobile(loginReq.getMobile()); + loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId()); + loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand()); loginUserInfo.setLastLoginIp(getIpAddr(request)); return Result.success(userInfoService.loginOrRegister(loginUserInfo)); } finally { @@ -131,15 +126,12 @@ public class LoginController extends BaseController { * authorization 续期 */ @ApiOperation(value = "3.token续期", notes = "有效期7天") - @ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true), - @ApiImplicitParam(name = "deviceBrand", value = "设备品牌", required = false) }) @PostMapping("/autoLogin") @GlobalInterceptor public Result autoLogin(HttpServletRequest request, @RequestHeader(value = "Authorization", required = false) String authorization, - @VerifyParam(required = true) @RequestParam("deviceId") String deviceId, - @RequestParam("deviceBrand") String deviceBrand) { - return Result.success(userInfoService.autoLogin(authorization, deviceId, deviceBrand, getIpAddr(request))); + @VerifyParam TokenRefreshReq tokenRefreshReq) { + return Result.success(userInfoService.autoLogin(authorization, tokenRefreshReq.getDeviceId(), tokenRefreshReq.getDeviceBrand(), getIpAddr(request))); } /** diff --git a/luoo_user/src/main/java/com/luoo/user/dto/request/FeedbackReq.java b/luoo_user/src/main/java/com/luoo/user/dto/request/FeedbackReq.java new file mode 100644 index 0000000..9be2fb8 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/request/FeedbackReq.java @@ -0,0 +1,33 @@ +package com.luoo.user.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import java.io.Serializable; +import java.util.List; + +import org.springframework.web.multipart.MultipartFile; + +import annotation.VerifyParam; + +/** + * 反馈请求 + */ +@Getter +@Setter +@ApiModel +public class FeedbackReq implements Serializable { + private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "反馈类型,3个值,0:bug, 1:建议,2:其它", required = true) + @VerifyParam(required = true) + private Integer type; + @ApiModelProperty(value = "反馈内容,最多300字", required = true) + @VerifyParam(required = true, max = 300) + private String content; + @ApiModelProperty(value = "图片,单张图片最大5M,一次上传最多10张图片", required = false) + private List files; + @ApiModelProperty(value = "联系方式(可选),最多50字", required = false) + @VerifyParam(max = 50) + private String contact; +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java b/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java new file mode 100644 index 0000000..4e46066 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/request/LoginReq.java @@ -0,0 +1,34 @@ +package com.luoo.user.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import java.io.Serializable; + +import annotation.VerifyParam; +import enums.VerifyRegexEnum; + +/** + * 期刊查询参数 + */ +@Getter +@Setter +@ApiModel +public class LoginReq implements Serializable { + private static final long serialVersionUID = 1L; + @ApiModelProperty(name = "mobile", value = "手机号", required = true) + @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE) + private String mobile; + + @ApiModelProperty(name = "mobileCheckCode", value = "6位验证码", required = true) + @VerifyParam(required = true, regex = VerifyRegexEnum.MOBILE_CHECK_CODE) + String mobileCheckCode; + + @ApiModelProperty(name = "deviceId", value = "设备id", required = true) + @VerifyParam(required = true) + private String deviceId; + + @ApiModelProperty(name = "deviceBrand", value = "设备品牌", required = false) + String deviceBrand; +} diff --git a/luoo_user/src/main/java/com/luoo/user/dto/request/TokenRefreshReq.java b/luoo_user/src/main/java/com/luoo/user/dto/request/TokenRefreshReq.java new file mode 100644 index 0000000..34f6c3f --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/request/TokenRefreshReq.java @@ -0,0 +1,25 @@ +package com.luoo.user.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import java.io.Serializable; + +import annotation.VerifyParam; + +/** + * 期刊查询参数 + */ +@Getter +@Setter +@ApiModel +public class TokenRefreshReq implements Serializable { + private static final long serialVersionUID = 1L; + @ApiModelProperty(name = "deviceId", value = "设备id", required = true) + @VerifyParam(required = true) + String deviceId; + + @ApiModelProperty(name = "deviceBrand", value = "设备品牌", required = false) + String deviceBrand; +}