diff --git a/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/req/FindUserByIdReqDTO.java b/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/req/FindUserByIdReqDTO.java new file mode 100644 index 0000000..f250ee1 --- /dev/null +++ b/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/req/FindUserByIdReqDTO.java @@ -0,0 +1,21 @@ +package com.hanserwei.hannote.user.dto.req; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FindUserByIdReqDTO { + + /** + * 用户ID + */ + @NotNull(message = "用户 ID 不能为空") + private Long id; + +} \ No newline at end of file diff --git a/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/resp/FindUserByIdRspDTO.java b/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/resp/FindUserByIdRspDTO.java new file mode 100644 index 0000000..0fb9df0 --- /dev/null +++ b/han-note-user/han-note-user-api/src/main/java/com/hanserwei/hannote/user/dto/resp/FindUserByIdRspDTO.java @@ -0,0 +1,28 @@ +package com.hanserwei.hannote.user.dto.resp; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FindUserByIdRspDTO { + + /** + * 用户 ID + */ + private Long id; + + /** + * 昵称 + */ + private String nickName; + + /** + * 头像 + */ + private String avatar; +} \ No newline at end of file diff --git a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/controller/UserController.java b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/controller/UserController.java index 3a0c739..98553b4 100644 --- a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/controller/UserController.java +++ b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/controller/UserController.java @@ -5,9 +5,11 @@ import com.hanserwei.framework.common.response.Response; import com.hanserwei.hannote.user.biz.model.vo.UpdateUserInfoReqVO; import com.hanserwei.hannote.user.biz.service.UserService; import com.hanserwei.hannote.user.dto.req.FindUserByEmailReqDTO; +import com.hanserwei.hannote.user.dto.req.FindUserByIdReqDTO; import com.hanserwei.hannote.user.dto.req.RegisterUserReqDTO; import com.hanserwei.hannote.user.dto.req.UpdateUserPasswordReqDTO; import com.hanserwei.hannote.user.dto.resp.FindUserByEmailRspDTO; +import com.hanserwei.hannote.user.dto.resp.FindUserByIdRspDTO; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -27,7 +29,7 @@ public class UserController { /** * 用户信息修改 - * + * * @param updateUserInfoReqVO 修改信息请求 * @return 响应 */ @@ -55,4 +57,10 @@ public class UserController { return userService.updatePassword(updateUserPasswordReqDTO); } + @PostMapping("/findById") + @ApiOperationLog(description = "查询用户信息") + public Response findById(@Validated @RequestBody FindUserByIdReqDTO findUserByIdReqDTO) { + return userService.findById(findUserByIdReqDTO); + } + } \ No newline at end of file diff --git a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/UserService.java b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/UserService.java index efbe969..986e72c 100644 --- a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/UserService.java +++ b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/UserService.java @@ -5,9 +5,11 @@ import com.hanserwei.framework.common.response.Response; import com.hanserwei.hannote.user.biz.domain.dataobject.UserDO; import com.hanserwei.hannote.user.biz.model.vo.UpdateUserInfoReqVO; import com.hanserwei.hannote.user.dto.req.FindUserByEmailReqDTO; +import com.hanserwei.hannote.user.dto.req.FindUserByIdReqDTO; import com.hanserwei.hannote.user.dto.req.RegisterUserReqDTO; import com.hanserwei.hannote.user.dto.req.UpdateUserPasswordReqDTO; import com.hanserwei.hannote.user.dto.resp.FindUserByEmailRspDTO; +import com.hanserwei.hannote.user.dto.resp.FindUserByIdRspDTO; public interface UserService extends IService { @@ -42,4 +44,12 @@ public interface UserService extends IService { * @return 响应结果 */ Response updatePassword(UpdateUserPasswordReqDTO updateUserPasswordReqDTO); + + /** + * 根据用户 ID 查询用户信息 + * + * @param findUserByIdReqDTO 查询用户信息请求参数 + * @return 响应结果 + */ + Response findById(FindUserByIdReqDTO findUserByIdReqDTO); } \ No newline at end of file diff --git a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/impl/UserServiceImpl.java b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/impl/UserServiceImpl.java index b0ea4d9..ce9b388 100644 --- a/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/impl/UserServiceImpl.java +++ b/han-note-user/han-note-user-biz/src/main/java/com/hanserwei/hannote/user/biz/service/impl/UserServiceImpl.java @@ -25,9 +25,11 @@ import com.hanserwei.hannote.user.biz.rpc.DistributedIdGeneratorRpcService; import com.hanserwei.hannote.user.biz.rpc.OssRpcService; import com.hanserwei.hannote.user.biz.service.UserService; import com.hanserwei.hannote.user.dto.req.FindUserByEmailReqDTO; +import com.hanserwei.hannote.user.dto.req.FindUserByIdReqDTO; import com.hanserwei.hannote.user.dto.req.RegisterUserReqDTO; import com.hanserwei.hannote.user.dto.req.UpdateUserPasswordReqDTO; import com.hanserwei.hannote.user.dto.resp.FindUserByEmailRspDTO; +import com.hanserwei.hannote.user.dto.resp.FindUserByIdRspDTO; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -204,7 +206,7 @@ public class UserServiceImpl extends ServiceImpl implement public Response findByEmail(FindUserByEmailReqDTO findUserByEmailReqDTO) { String email = findUserByEmailReqDTO.getEmail(); UserDO userDO = this.getOne(new QueryWrapper().eq("email", email)); - if (Objects.isNull(userDO)){ + if (Objects.isNull(userDO)) { throw new ApiException(ResponseCodeEnum.USER_NOT_FOUND); } // 构建返参 @@ -229,5 +231,23 @@ public class UserServiceImpl extends ServiceImpl implement // 更新用户密码 return updateById(userDO) ? Response.success() : Response.fail(); } + + @Override + public Response findById(FindUserByIdReqDTO findUserByIdReqDTO) { + Long userId = findUserByIdReqDTO.getId(); + UserDO userDO = this.getOne(new QueryWrapper().eq("id", userId)); + + // 判空 + if (Objects.isNull(userDO)) { + throw new ApiException(ResponseCodeEnum.USER_NOT_FOUND); + } + // 构建返参 + FindUserByIdRspDTO findUserByIdRspDTO = FindUserByIdRspDTO.builder() + .id(userDO.getId()) + .nickName(userDO.getNickname()) + .avatar(userDO.getAvatar()) + .build(); + return Response.success(findUserByIdRspDTO); + } }