Commit 728d3c75 by 张晋雄

完善修改用户基本信息规范

parent f36b2f9c
...@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.core.annotation.Anonymous; ...@@ -6,6 +6,7 @@ import cn.meteor.beyondclouds.core.annotation.Anonymous;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject; import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response; import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.bean.Subject; import cn.meteor.beyondclouds.core.bean.Subject;
import cn.meteor.beyondclouds.core.validation.groups.UpdateGroup;
import cn.meteor.beyondclouds.modules.user.entity.User; import cn.meteor.beyondclouds.modules.user.entity.User;
import cn.meteor.beyondclouds.modules.user.entity.UserFollow; import cn.meteor.beyondclouds.modules.user.entity.UserFollow;
import cn.meteor.beyondclouds.modules.user.exception.UserServiceException; import cn.meteor.beyondclouds.modules.user.exception.UserServiceException;
...@@ -21,6 +22,7 @@ import io.swagger.annotations.ApiOperation; ...@@ -21,6 +22,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -67,8 +69,8 @@ public class UserApi { ...@@ -67,8 +69,8 @@ public class UserApi {
@ApiOperation("修改我的基本信息") @ApiOperation("修改我的基本信息")
@PutMapping("/my/baseinfo") @PutMapping("/my/baseinfo")
public Response alterBaseInfo(@RequestBody @Valid UserBaseInfoFrom userBaseinfoFrom, BindingResult result, public Response alterBaseInfo(@RequestBody @Validated(UpdateGroup.class) UserBaseInfoFrom userBaseinfoFrom, BindingResult result,
@CurrentSubject Subject subject){ @CurrentSubject Subject subject) throws UserServiceException {
if (result.hasErrors()) { if (result.hasErrors()) {
return Response.fieldError(result.getFieldError()); return Response.fieldError(result.getFieldError());
} }
......
...@@ -17,7 +17,8 @@ public enum UserErrorCode implements IErrorCode { ...@@ -17,7 +17,8 @@ public enum UserErrorCode implements IErrorCode {
FOLLOWED_USER_NOT_EXISTS(1004, "被关注用户不存在"), FOLLOWED_USER_NOT_EXISTS(1004, "被关注用户不存在"),
FOLLOWER_USER_NOT_EXISTS(1005, "关注者不存在"), FOLLOWER_USER_NOT_EXISTS(1005, "关注者不存在"),
ALREADY_FOLLOWED(1006, "已关注过该用户"), ALREADY_FOLLOWED(1006, "已关注过该用户"),
NON_FOLLOWED(1007, "没有关注过该用户"); NON_FOLLOWED(1007, "没有关注过该用户"),
NICKNAME_ALREADY_EXIST(1008,"该昵称已存在");
UserErrorCode(long code, String msg) { UserErrorCode(long code, String msg) {
this.code = code; this.code = code;
......
package cn.meteor.beyondclouds.modules.user.form; package cn.meteor.beyondclouds.modules.user.form;
import cn.meteor.beyondclouds.core.constant.RegexPatterns;
import cn.meteor.beyondclouds.core.validation.constraints.NullOrNotBlank;
import cn.meteor.beyondclouds.core.validation.groups.UpdateGroup;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Pattern;
/** /**
* @program: beyond-clouds * @program: beyond-clouds
* @description: 用户信息表 * @description: 用户信息表
...@@ -13,17 +21,32 @@ import lombok.Data; ...@@ -13,17 +21,32 @@ import lombok.Data;
@ApiModel("用户信息表") @ApiModel("用户信息表")
public class UserBaseInfoFrom { public class UserBaseInfoFrom {
@ApiModelProperty("昵称")
@NullOrNotBlank(message = "请传入有效的昵称", groups = UpdateGroup.class)
private String nickName; private String nickName;
@ApiModelProperty("头像")
@NullOrNotBlank(message = "请选择有效的头像", groups = UpdateGroup.class)
private String userAvatar; private String userAvatar;
@ApiModelProperty("性别")
@Max(value = 2, message = "请输入有效性别")
@Min(value = 0, message = "请输入有效性别")
private Integer gender; private Integer gender;
@ApiModelProperty("签名")
@NullOrNotBlank(message = "请传入有效的签名", groups = UpdateGroup.class)
private String signature; private String signature;
@ApiModelProperty("手机号")
@Pattern(regexp = RegexPatterns.MOBILE, message = "手机号格式不正确")
private String mobile; private String mobile;
@ApiModelProperty("微信号")
@NullOrNotBlank(message = "请传入有效的微信号", groups = UpdateGroup.class)
private String wxNumber; private String wxNumber;
@ApiModelProperty("qq号")
@NullOrNotBlank(message = "请传入有效的qq号", groups = UpdateGroup.class)
private String qqNumber; private String qqNumber;
} }
...@@ -45,7 +45,7 @@ public interface IUserService extends IService<User> { ...@@ -45,7 +45,7 @@ public interface IUserService extends IService<User> {
* 修改用户基本信息 * 修改用户基本信息
* @param user * @param user
*/ */
void alterBaseInfo(User user); void alterBaseInfo(User user) throws UserServiceException;
/** /**
* 修改密码 * 修改密码
......
...@@ -63,6 +63,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I ...@@ -63,6 +63,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
User user = new User(); User user = new User();
user.setNickName("自动生成的昵称"); user.setNickName("自动生成的昵称");
user.setSignature("自动生成的默认签名"); user.setSignature("自动生成的默认签名");
user.setMobile(mobile);
save(user); save(user);
//4. 创建认证信息 //4. 创建认证信息
...@@ -116,7 +117,13 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I ...@@ -116,7 +117,13 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
} }
@Override @Override
public void alterBaseInfo(User user) { public void alterBaseInfo(User user) throws UserServiceException {
//查看昵称是否重复
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("nick_name", user.getNickName());
if(null != getOne(queryWrapper)){
throw new UserServiceException(UserErrorCode.NICKNAME_ALREADY_EXIST);
}
updateById(user); updateById(user);
} }
......
...@@ -3,7 +3,7 @@ spring: ...@@ -3,7 +3,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root username: root
password: 100Centa30821%mysql password: 2018006709
swagger: swagger:
enable: true enable: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment