mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-31 17:40:05 +08:00
1. 合并 member 修改昵称和头像接口,统一成修改基本信息 API
This commit is contained in:
parent
94a32d34b2
commit
4153331535
@ -2,13 +2,3 @@
|
||||
GET {{appApi}}/member/user/get
|
||||
Authorization: Bearer test245
|
||||
tenant-id: {{appTenentId}}
|
||||
|
||||
### 请求 /member/user/profile/revise-nickname 接口 成功
|
||||
PUT {{appApi}}/member/user/update-nickname?nickname=yunai222
|
||||
Authorization: Bearer test245
|
||||
tenant-id: {{appTenentId}}
|
||||
|
||||
### 请求 /member/user/get-user-info 接口 成功
|
||||
GET {{appApi}}/member/user/get-user-info?id=245
|
||||
Authorization: Bearer test245
|
||||
tenant-id: {{appTenentId}}
|
||||
|
@ -2,25 +2,23 @@ package cn.iocoder.yudao.module.member.controller.app.user;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_IS_EMPTY;
|
||||
|
||||
@Tag(name = "用户 APP - 用户个人中心")
|
||||
@RestController
|
||||
@ -32,29 +30,18 @@ public class AppMemberUserController {
|
||||
@Resource
|
||||
private MemberUserService userService;
|
||||
|
||||
@PutMapping("/update-nickname")
|
||||
@Operation(summary = "修改用户昵称")
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改基本信息")
|
||||
@PreAuthenticated
|
||||
public CommonResult<Boolean> updateUserNickname(@RequestParam("nickname") String nickname) {
|
||||
userService.updateUserNickname(getLoginUserId(), nickname);
|
||||
public CommonResult<Boolean> updateUser(@RequestBody @Valid AppMemberUserUpdateReqVO reqVO) {
|
||||
userService.updateUser(getLoginUserId(), reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/update-avatar")
|
||||
@Operation(summary = "修改用户头像")
|
||||
@PreAuthenticated
|
||||
public CommonResult<String> updateUserAvatar(@RequestParam("avatarFile") MultipartFile file) throws Exception {
|
||||
if (file.isEmpty()) {
|
||||
throw exception(FILE_IS_EMPTY);
|
||||
}
|
||||
String avatar = userService.updateUserAvatar(getLoginUserId(), file.getInputStream());
|
||||
return success(avatar);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得基本信息")
|
||||
@PreAuthenticated
|
||||
public CommonResult<AppUserInfoRespVO> getUserInfo() {
|
||||
public CommonResult<AppMemberUserInfoRespVO> getUserInfo() {
|
||||
MemberUserDO user = userService.getUser(getLoginUserId());
|
||||
return success(MemberUserConvert.INSTANCE.convert(user));
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AppUserInfoRespVO {
|
||||
public class AppMemberUserInfoRespVO {
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||
private String nickname;
|
@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.member.controller.app.user.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
@Schema(description = "用户 App - 会员用户更新 Request VO")
|
||||
@Data
|
||||
public class AppMemberUserUpdateReqVO {
|
||||
|
||||
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
private String nickname;
|
||||
|
||||
@Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/x.png")
|
||||
@URL(message = "头像必须是 URL 格式")
|
||||
private String avatar;
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserInfoRespVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
@ -16,7 +16,7 @@ public interface MemberUserConvert {
|
||||
|
||||
MemberUserConvert INSTANCE = Mappers.getMapper(MemberUserConvert.class);
|
||||
|
||||
AppUserInfoRespVO convert(MemberUserDO bean);
|
||||
AppMemberUserInfoRespVO convert(MemberUserDO bean);
|
||||
|
||||
MemberUserRespDTO convert2(MemberUserDO bean);
|
||||
|
||||
|
@ -4,11 +4,11 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.validation.Mobile;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -70,26 +70,17 @@ public interface MemberUserService {
|
||||
List<MemberUserDO> getUserList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 【会员】修改用户昵称
|
||||
* 【会员】修改基本信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param nickname 用户新昵称
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 基本信息
|
||||
*/
|
||||
void updateUserNickname(Long userId, String nickname);
|
||||
|
||||
/**
|
||||
* 【会员】修改用户头像
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param inputStream 头像文件
|
||||
* @return 头像url
|
||||
*/
|
||||
String updateUserAvatar(Long userId, InputStream inputStream) throws Exception;
|
||||
void updateUser(Long userId, AppMemberUserUpdateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 【会员】修改手机
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param userId 用户编号
|
||||
* @param reqVO 请求实体
|
||||
*/
|
||||
void updateUserMobile(Long userId, AppUserUpdateMobileReqVO reqVO);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.member.service.user;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
@ -8,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserPageReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppMemberUserUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserUpdateMobileReqVO;
|
||||
import cn.iocoder.yudao.module.member.convert.user.MemberUserConvert;
|
||||
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
|
||||
@ -23,7 +23,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -105,26 +104,9 @@ public class MemberUserServiceImpl implements MemberUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserNickname(Long userId, String nickname) {
|
||||
MemberUserDO user = this.validateUserExists(userId);
|
||||
// 仅当新昵称不等于旧昵称时进行修改
|
||||
if (nickname.equals(user.getNickname())){
|
||||
return;
|
||||
}
|
||||
MemberUserDO userDO = new MemberUserDO();
|
||||
userDO.setId(user.getId());
|
||||
userDO.setNickname(nickname);
|
||||
memberUserMapper.updateById(userDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateUserAvatar(Long userId, InputStream avatarFile) {
|
||||
validateUserExists(userId);
|
||||
// 创建文件
|
||||
String avatar = fileApi.createFile(IoUtil.readBytes(avatarFile));
|
||||
// 更新头像路径
|
||||
memberUserMapper.updateById(MemberUserDO.builder().id(userId).avatar(avatar).build());
|
||||
return avatar;
|
||||
public void updateUser(Long userId, AppMemberUserUpdateReqVO reqVO) {
|
||||
memberUserMapper.updateById(new MemberUserDO().setId(userId)
|
||||
.setNickname(reqVO.getNickname()).setAvatar(reqVO.getAvatar()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,7 +67,7 @@ public class MemberUserServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
String newNickName = randomString();
|
||||
|
||||
// 调用接口修改昵称
|
||||
memberUserService.updateUserNickname(userDO.getId(),newNickName);
|
||||
memberUserService.updateUser(userDO.getId(),newNickName);
|
||||
// 查询新修改后的昵称
|
||||
String nickname = memberUserService.getUser(userDO.getId()).getNickname();
|
||||
// 断言
|
||||
|
Loading…
Reference in New Issue
Block a user