新增人生轨迹模块代码

This commit is contained in:
2025-12-21 17:44:59 +08:00
parent f3c06ce6af
commit cfd12f01db
14 changed files with 1156 additions and 72 deletions
@@ -0,0 +1,100 @@
package com.emotion.controller;
import com.emotion.common.PageResult;
import com.emotion.common.Result;
import com.emotion.dto.request.userprofile.UserProfileCreateRequest;
import com.emotion.dto.request.userprofile.UserProfilePageRequest;
import com.emotion.dto.request.userprofile.UserProfileUpdateRequest;
import com.emotion.dto.response.userprofile.UserProfileResponse;
import com.emotion.service.UserProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* 用户档案控制器
*
* @author huazhongmin
* @date 2025-12-21
*/
@RestController
@RequestMapping("/user-profile")
public class UserProfileController {
@Autowired
private UserProfileService userProfileService;
/**
* 新增档案
*/
@PostMapping("/create")
public Result<UserProfileResponse> create(@Valid @RequestBody UserProfileCreateRequest request) {
UserProfileResponse response = userProfileService.createProfile(request);
return Result.success(response);
}
/**
* 删除档案
*/
@DeleteMapping("/delete")
public Result<Void> delete(@RequestParam String id) {
boolean success = userProfileService.deleteProfile(id);
if (success) {
return Result.success();
} else {
return Result.error("删除失败");
}
}
/**
* 修改档案
*/
@PutMapping("/update")
public Result<UserProfileResponse> update(@Valid @RequestBody UserProfileUpdateRequest request) {
UserProfileResponse response = userProfileService.updateProfile(request);
return Result.success(response);
}
/**
* 根据ID查询详情
*/
@GetMapping("/detail")
public Result<UserProfileResponse> getById(@RequestParam String id) {
UserProfileResponse response = userProfileService.getProfileById(id);
if (response == null) {
return Result.notFound("档案不存在");
}
return Result.success(response);
}
/**
* 获取当前登录用户的档案
*/
@GetMapping("/me")
public Result<UserProfileResponse> getCurrentProfile() {
UserProfileResponse response = userProfileService.getCurrentUserProfile();
// 如果不存在,返回null data,不报错
return Result.success(response);
}
/**
* 分页查询
*/
@GetMapping("/page")
public Result<PageResult<UserProfileResponse>> getPage(@Validated UserProfilePageRequest request) {
PageResult<UserProfileResponse> pageResult = userProfileService.getProfilePage(request);
return Result.success(pageResult);
}
/**
* 列表查询
*/
@GetMapping("/list")
public Result<List<UserProfileResponse>> getList(@Validated UserProfilePageRequest request) {
List<UserProfileResponse> list = userProfileService.getProfileList(request);
return Result.success(list);
}
}