소스 검색

用户个人信息查看和修改接口开发

qizai 1 년 전
부모
커밋
34b3de9b7e

+ 36 - 0
src/main/java/com/chelvc/cloud/maintain/controller/UserController.java

@@ -1,12 +1,26 @@
 package com.chelvc.cloud.maintain.controller;
 
+import com.chelvc.cloud.maintain.copier.UserCopier;
+import com.chelvc.cloud.maintain.vo.UserVO;
+import com.chelvc.cloud.uc.api.dto.UserDTO;
+import com.chelvc.cloud.uc.api.param.UserModifyParam;
 import com.chelvc.cloud.uc.api.service.UserService;
 import com.chelvc.framework.base.annotation.ResponseWrapping;
+import com.chelvc.framework.base.context.SessionContextHolder;
+import com.chelvc.framework.base.util.ResourceUtils;
+import com.chelvc.framework.common.util.ErrorUtils;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.validation.Valid;
+import javax.validation.constraints.Min;
+
 /**
  * 用户接口
  *
@@ -27,4 +41,26 @@ public class UserController {
     public void unregister() {
         this.userService.unregister();
     }
+
+    /**
+     * 获取用户信息
+     *
+     * @return 用户信息
+     */
+    @GetMapping("/user/info")
+    public UserVO getUserInfo() {
+        UserDTO user = this.userService.getUser();
+        ResourceUtils.required(user, "用户不存在");
+        return UserCopier.INSTANCE.copying(user);
+    }
+
+    /**
+     * 修改用户信息
+     *
+     * @param param 修改参数
+     */
+    @PutMapping("/user/info")
+    public void updateUser(@RequestBody @Valid UserModifyParam param) {
+        this.userService.updateUser(param);
+    }
 }

+ 44 - 0
src/main/java/com/chelvc/cloud/maintain/copier/UserCopier.java

@@ -0,0 +1,44 @@
+package com.chelvc.cloud.maintain.copier;
+
+import com.chelvc.cloud.maintain.vo.UserVO;
+import com.chelvc.cloud.uc.api.dto.UserDTO;
+import org.mapstruct.Builder;
+import org.mapstruct.IterableMapping;
+import org.mapstruct.Mapper;
+import org.mapstruct.Named;
+import org.mapstruct.factory.Mappers;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 用户对象拷贝接口
+ *
+ * @author qizai
+ * @Date 2023/9/8
+ **/
+@Mapper(builder = @Builder(disableBuilder = true))
+public interface UserCopier {
+    /**
+     * 对象拷贝接口实例
+     */
+    UserCopier INSTANCE = Mappers.getMapper(UserCopier.class);
+
+    /**
+     * 用户信息拷贝
+     *
+     * @param user 用户信息
+     * @return 用户信息
+     */
+    @Named("dto2vo")
+    UserVO copying(UserDTO user);
+
+    /**
+     * 用户信息拷贝
+     *
+     * @param users 用户信息集合
+     * @return 用户信息列表
+     */
+    @IterableMapping(qualifiedByName = "dto2vo")
+    List<UserVO> copying(Collection<UserDTO> users);
+}

+ 26 - 0
src/main/java/com/chelvc/cloud/maintain/vo/UserVO.java

@@ -1,6 +1,7 @@
 package com.chelvc.cloud.maintain.vo;
 
 import java.io.Serializable;
+import java.util.Date;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -23,6 +24,11 @@ public class UserVO implements Serializable {
      */
     private Long id;
 
+    /**
+     * 用户名
+     */
+    private String username;
+
     /**
      * 用户头像
      */
@@ -32,4 +38,24 @@ public class UserVO implements Serializable {
      * 用户昵称
      */
     private String nickname;
+
+    /**
+     * 性别
+     */
+    private String gender;
+
+    /**
+     * 常用地
+     */
+    private String useCity;
+
+    /**
+     * 个人介绍
+     */
+    private String introduction;
+
+    /**
+     * 生日
+     */
+    private Date birthday;
 }