增加用户修改自己头像和昵称

This commit is contained in:
YunaiV 2019-03-10 20:39:01 +08:00
parent e771a9a5ae
commit 3ffdc44669
15 changed files with 131 additions and 46 deletions

View File

@ -7,7 +7,7 @@ import cn.iocoder.mall.user.service.api.MobileCodeService;
import cn.iocoder.mall.user.service.api.OAuth2Service;
import cn.iocoder.mall.user.service.api.UserService;
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
import cn.iocoder.mall.user.application.vo.MobileRegisterVO;
import cn.iocoder.mall.user.application.vo.users.MobileRegisterVO;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("user/passport")
@RequestMapping("users/passport")
@Api("Passport 模块")
public class PassportController {

View File

@ -1,9 +1,11 @@
package cn.iocoder.mall.user.application.controller.users;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.application.convert.UserConvert;
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
import cn.iocoder.mall.user.application.vo.UsersUserVO;
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
import cn.iocoder.mall.user.service.api.UserService;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
@ -15,15 +17,14 @@ import org.springframework.web.bind.annotation.*;
@Api("用户模块")
public class UserController {
@Reference
@Reference(validation = "true")
private UserService userService;
@GetMapping("/info")
@ApiOperation(value = "用户信息")
public CommonResult<UsersUserVO> info() {
// TODO 芋艿正在实现中
UsersUserVO user = new UsersUserVO().setId(UserSecurityContextHolder.getContext().getUserId());
return CommonResult.success(user);
CommonResult<UserBO> userResult = userService.getUser(UserSecurityContextHolder.getContext().getUserId());
return UserConvert.INSTANCE.convert2(userResult);
}
@PostMapping("/update_avatar")

View File

@ -2,7 +2,7 @@ package cn.iocoder.mall.user.application.convert;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.service.api.bo.OAuth2AccessTokenBO;
import cn.iocoder.mall.user.application.vo.MobileRegisterVO;
import cn.iocoder.mall.user.application.vo.users.MobileRegisterVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

View File

@ -2,6 +2,8 @@ package cn.iocoder.mall.user.application.convert;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import cn.iocoder.mall.user.service.api.bo.UserPageBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
@ -15,4 +17,7 @@ public interface UserConvert {
@Mappings({})
CommonResult<AdminsUserPageVO> convert(CommonResult<UserPageBO> result);
}
@Mappings({})
CommonResult<UsersUserVO> convert2(CommonResult<UserBO> result);
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.mall.user.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel("用户信息 VO")
public class UsersUserVO {
@ApiModelProperty(value = "用户编号", required = true, example = "123")
private Integer id;
public Integer getId() {
return id;
}
public UsersUserVO setId(Integer id) {
this.id = id;
return this;
}
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.mall.user.application.vo;
package cn.iocoder.mall.user.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

View File

@ -0,0 +1,54 @@
package cn.iocoder.mall.user.application.vo.users;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel("用户信息 VO")
public class UsersUserVO {
@ApiModelProperty(value = "用户编号", required = true, example = "123")
private Integer id;
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
private String mobile;
@ApiModelProperty(value = "昵称", required = true, example = "小王")
private String nickname;
@ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg")
private String avatar;
public Integer getId() {
return id;
}
public UsersUserVO setId(Integer id) {
this.id = id;
return this;
}
public String getMobile() {
return mobile;
}
public UsersUserVO setMobile(String mobile) {
this.mobile = mobile;
return this;
}
public String getNickname() {
return nickname;
}
public UsersUserVO setNickname(String nickname) {
this.nickname = nickname;
return this;
}
public String getAvatar() {
return avatar;
}
public UsersUserVO setAvatar(String avatar) {
this.avatar = avatar;
return this;
}
}

View File

@ -38,7 +38,7 @@ public class UserSecurityInterceptor extends HandlerInterceptorAdapter {
}
authentication = result.getData();
// 添加到 SecurityContext
UserSecurityContext context = new UserSecurityContext(authentication.getUid());
UserSecurityContext context = new UserSecurityContext(authentication.getUserId());
UserSecurityContextHolder.setContext(context);
}
// 校验是否需要已授权

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.user.service.api;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import cn.iocoder.mall.user.service.api.bo.UserPageBO;
import cn.iocoder.mall.user.service.api.dto.UserPageDTO;
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
@ -9,6 +10,8 @@ public interface UserService {
CommonResult<UserPageBO> getUserPage(UserPageDTO userPageDTO);
CommonResult<UserBO> getUser(Integer userId);
/**
* 更新用户基本信息
*

View File

@ -7,14 +7,14 @@ public class OAuth2AuthenticationBO implements Serializable {
/**
* 用户编号
*/
private Integer uid;
private Integer userId;
public Integer getUid() {
return uid;
public Integer getUserId() {
return userId;
}
public OAuth2AuthenticationBO setUid(Integer uid) {
this.uid = uid;
public OAuth2AuthenticationBO setUserId(Integer userId) {
this.userId = userId;
return this;
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.mall.user.service;
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.util.ValidationUtil;
import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.user.dao.MobileCodeMapper;
import cn.iocoder.mall.user.dataobject.MobileCodeDO;
@ -77,10 +79,8 @@ public class MobileCodeServiceImpl implements MobileCodeService {
// TODO 芋艿后面要返回有效时间
public CommonResult<Void> send(String mobile) {
// TODO 芋艿校验手机格式
// 校验手机号码是否已经注册
if (userService.getUser(mobile) != null) {
return ServiceExceptionUtil.error(UserErrorCodeEnum.USER_MOBILE_ALREADY_REGISTERED.getCode());
if (!ValidationUtil.isMobile(mobile)) {
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "手机格式不正确"); // TODO 有点搓
}
// 校验是否可以发送验证码
MobileCodeDO lastMobileCodePO = mobileCodeMapper.selectLast1ByMobile(mobile);

View File

@ -11,6 +11,7 @@ import cn.iocoder.mall.user.dao.UserRegisterMapper;
import cn.iocoder.mall.user.dataobject.UserDO;
import cn.iocoder.mall.user.dataobject.UserRegisterDO;
import cn.iocoder.mall.user.service.api.UserService;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import cn.iocoder.mall.user.service.api.bo.UserPageBO;
import cn.iocoder.mall.user.service.api.constant.UserConstants;
import cn.iocoder.mall.user.service.api.constant.UserErrorCodeEnum;
@ -76,6 +77,11 @@ public class UserServiceImpl implements UserService {
return CommonResult.success(userPageBO);
}
@Override
public CommonResult<UserBO> getUser(Integer userId) {
return CommonResult.success(UserConvert.INSTANCE.convert(userMapper.selectById(userId)));
}
@Override
public CommonResult<Boolean> updateUser(UserUpdateDTO userUpdateDTO) {
// 校验用户存在

View File

@ -5,7 +5,7 @@
<insert id="insert" parameterType="MobileCodeDO">
INSERT INTO mobile_code (
id, mobile, code, today_index, used,
used_uid, used_time, create_time
userd_user_id, used_time, create_time
) VALUES (
#{id}, #{mobile}, #{code}, #{todayIndex}, #{used},
#{usedUserId}, #{usedTime}, #{createTime}
@ -16,7 +16,7 @@
UPDATE mobile_code
<set>
<if test="used != null"> used = #{used}, </if>
<if test="usedUserId != null"> used_uid = #{usedUserId}, </if>
<if test="usedUserId != null"> userd_user_id = #{usedUserId}, </if>
<if test="usedTime != null"> used_time = #{usedTime}, </if>
</set>
WHERE id = #{id}
@ -25,7 +25,7 @@
<select id="selectLast1ByMobile" parameterType="String" resultType="MobileCodeDO">
SELECT
id, mobile, code, today_index, used,
used_uid, used_time, create_time
userd_user_id, used_time, create_time
FROM mobile_code
WHERE mobile = #{mobile}
ORDER BY id DESC

View File

@ -14,7 +14,7 @@
<select id="selectByTokenId" parameterType="String" resultType="OAuth2AccessTokenDO">
SELECT
id, adminId, valid, expires_time
id, user_id, valid, expires_time
FROM oauth2_access_token
WHERE id = #{id}
</select>

View File

@ -2,11 +2,14 @@ package cn.iocoder.mall.user.convert;
import cn.iocoder.mall.user.dataobject.UserDO;
import cn.iocoder.mall.user.service.api.bo.UserBO;
import cn.iocoder.mall.user.service.api.dto.UserUpdateDTO;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2019-03-08T17:14:01+0800",
date = "2019-03-10T20:36:11+0800",
comments = "version: 1.3.0.Final, compiler: javac, environment: Java 11.0.1 (Oracle Corporation)"
)
public class UserConvertImpl implements UserConvert {
@ -19,8 +22,42 @@ public class UserConvertImpl implements UserConvert {
UserBO userBO = new UserBO();
userBO.setId( userDO.getId() );
userBO.setMobile( userDO.getMobile() );
userBO.setNickname( userDO.getNickname() );
userBO.setAvatar( userDO.getAvatar() );
userBO.setStatus( userDO.getStatus() );
userBO.setCreateTime( userDO.getCreateTime() );
return userBO;
}
@Override
public UserDO convert(UserUpdateDTO userUpdateDTO) {
if ( userUpdateDTO == null ) {
return null;
}
UserDO userDO = new UserDO();
userDO.setId( userUpdateDTO.getId() );
userDO.setNickname( userUpdateDTO.getNickname() );
userDO.setAvatar( userUpdateDTO.getAvatar() );
return userDO;
}
@Override
public List<UserBO> convert(List<UserDO> userDOs) {
if ( userDOs == null ) {
return null;
}
List<UserBO> list = new ArrayList<UserBO>( userDOs.size() );
for ( UserDO userDO : userDOs ) {
list.add( convert( userDO ) );
}
return list;
}
}