diff --git a/pom.xml b/pom.xml index 4af5bd7..2ecd2c2 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,15 @@ test + + + + org.springframework.boot + spring-boot-starter-validation + + + + com.github.xiaoymin @@ -116,7 +125,7 @@ spring-boot-starter-data-redis - + com.google.code.gson gson diff --git a/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java b/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java index 23be05c..b20b04d 100644 --- a/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java +++ b/src/main/java/com/greenorange/promotion/controller/user/UserInfoController.java @@ -3,7 +3,6 @@ package com.greenorange.promotion.controller.user; import com.auth0.jwt.interfaces.DecodedJWT; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.net.HttpHeaders; import com.greenorange.promotion.annotation.RequiresPermission; import com.greenorange.promotion.common.BaseResponse; import com.greenorange.promotion.common.ErrorCode; @@ -23,17 +22,15 @@ import com.greenorange.promotion.service.common.CommonService; import com.greenorange.promotion.service.user.UserInfoService; import com.greenorange.promotion.utils.JWTUtils; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; import java.util.List; import java.util.concurrent.TimeUnit; @@ -109,13 +106,14 @@ public class UserInfoController { */ @PostMapping("add") @Operation(summary = "web端管理员添加用户表", description = "参数:用户表添加请求体,权限:管理员(boss, admin),方法名:addUserInfo") - public BaseResponse addUserInfo(@RequestBody @Valid UserInfoAddRequest userInfoAddRequest) { + public BaseResponse addUserInfo(@Valid @RequestBody UserInfoAddRequest userInfoAddRequest) { UserInfo userInfo = commonService.copyProperties(userInfoAddRequest, UserInfo.class); userInfoService.save(userInfo); return ResultUtils.success(true); } + /** * web端管理员更新用户表 * @param userInfoUpdateRequest 用户表更新请求体 @@ -123,7 +121,7 @@ public class UserInfoController { */ @PostMapping("update") @Operation(summary = "web端管理员更新用户表", description = "参数:用户表更新请求体,权限:管理员(boss, admin),方法名:updateUserInfo") - public BaseResponse updateUserInfo(@RequestBody @Valid UserInfoUpdateRequest userInfoUpdateRequest) { + public BaseResponse updateUserInfo(@RequestBody UserInfoUpdateRequest userInfoUpdateRequest) { ThrowUtils.throwIf(userInfoUpdateRequest == null || userInfoUpdateRequest.getId() <= 0, ErrorCode.PARAMS_ERROR); UserInfo userInfo = commonService.copyProperties(userInfoUpdateRequest, UserInfo.class); userInfoService.updateById(userInfo); diff --git a/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java b/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java index 1c39632..2368d2a 100644 --- a/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java +++ b/src/main/java/com/greenorange/promotion/model/dto/user/UserInfoAddRequest.java @@ -1,9 +1,8 @@ package com.greenorange.promotion.model.dto.user; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; import lombok.Data; - -import javax.validation.constraints.NotBlank; import java.io.Serial; import java.io.Serializable; @@ -19,59 +18,60 @@ public class UserInfoAddRequest implements Serializable { * 用户昵称 */ @NotBlank(message = "参数不能为空") - @Schema(description = "用户昵称", example = "${field.example}") + @Schema(description = "用户昵称", example = "chenxinzhi") private String nickName; /** * 用户头像URL */ - @Schema(description = "用户头像URL", example = "${field.example}") + @NotBlank(message = "参数不能为空") + @Schema(description = "用户头像URL", example = "http://xxx.png") private String userAvatar; /** * 手机号 */ @NotBlank(message = "参数不能为空") - @Schema(description = "手机号", example = "${field.example}") + @Schema(description = "手机号", example = "15888610253") private String phoneNumber; /** * 账号 */ @NotBlank(message = "参数不能为空") - @Schema(description = "账号", example = "${field.example}") + @Schema(description = "账号", example = "qingcheng_account") private String userAccount; /** * 密码 */ @NotBlank(message = "参数不能为空") - @Schema(description = "密码", example = "${field.example}") + @Schema(description = "密码", example = "qingcheng_password") private String userPassword; /** * 邀请码 */ - @Schema(description = "邀请码", example = "${field.example}") + @Schema(description = "邀请码", example = "666999") private String invitationCode; /** * 用户角色 */ @NotBlank(message = "参数不能为空") - @Schema(description = "用户角色", example = "${field.example}") + @Schema(description = "用户角色", example = "user") private String userRole; /** * 上级用户id */ - @Schema(description = "上级用户id", example = "${field.example}") + @Schema(description = "上级用户id", example = "1") private Long parentUserId; /** * 上级用户列表(1,2,3) */ - @Schema(description = "上级用户列表(1,2,3)", example = "${field.example}") + @Schema(description = "上级用户列表(1,2,3)", example = "1, 2, 3") private String superUserList; diff --git a/src/main/java/com/greenorange/promotion/model/entity/UserInfo.java b/src/main/java/com/greenorange/promotion/model/entity/UserInfo.java index e27b17f..f9a2851 100644 --- a/src/main/java/com/greenorange/promotion/model/entity/UserInfo.java +++ b/src/main/java/com/greenorange/promotion/model/entity/UserInfo.java @@ -8,6 +8,8 @@ import java.io.Serializable; import java.util.Date; import lombok.Data; +import javax.validation.constraints.NotNull; + /** * 用户基本信息表 * @TableName user_info diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7bf1d85..be5d1ab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,6 @@ spring: - data: redis: port: 6379