package com.emotion.controller; import com.emotion.common.PageResult; import com.emotion.common.Result; import com.emotion.dto.request.LifePathCreateRequest; import com.emotion.dto.request.LifePathPageRequest; import com.emotion.dto.request.LifePathUpdateRequest; import com.emotion.dto.response.LifePathResponse; import com.emotion.service.LifePathService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; 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-22 */ @RestController @RequestMapping("/lifePath") @Tag(name = "实现路径管理", description = "人生剧本实现路径的查询、创建、更新和删除接口") public class LifePathController { @Autowired private LifePathService lifePathService; /** * 分页查询当前用户的实现路径 */ @Operation(summary = "分页查询实现路径", description = "分页查询当前用户的实现路径列表。") @GetMapping(value = "/page") public Result> getPage(@Validated LifePathPageRequest request) { PageResult pageResult = lifePathService.getPageByCurrentUser(request); return Result.success(pageResult); } /** * 获取当前用户的所有实现路径列表 */ @Operation(summary = "获取实现路径列表", description = "获取当前用户的所有实现路径列表。") @GetMapping(value = "/listAll") public Result> getList() { List paths = lifePathService.getListByCurrentUser(); return Result.success(paths); } /** * 根据剧本ID获取实现路径 */ @Operation(summary = "根据剧本ID获取路径", description = "根据剧本 ID 获取对应的实现路径。") @GetMapping(value = "/byScript") public Result getByScriptId(@Parameter(description = "剧本 ID") @RequestParam String scriptId) { LifePathResponse path = lifePathService.getByScriptId(scriptId); if (path == null) { return Result.notFound("实现路径不存在"); } return Result.success(path); } /** * 根据ID获取实现路径详情 */ @Operation(summary = "获取路径详情", description = "根据 ID 获取实现路径的详细信息。") @GetMapping(value = "/detail") public Result getById(@Parameter(description = "路径 ID") @RequestParam String id) { LifePathResponse path = lifePathService.getPathById(id); if (path == null) { return Result.notFound("实现路径不存在"); } return Result.success(path); } /** * 创建实现路径 */ @Operation(summary = "创建实现路径", description = "创建一条新的实现路径。") @PostMapping(value = "/create") public Result create(@Valid @RequestBody LifePathCreateRequest request) { LifePathResponse path = lifePathService.createPath(request); if (path == null) { return Result.error("创建失败"); } return Result.success(path); } /** * 更新实现路径 */ @Operation(summary = "更新实现路径", description = "修改已有实现路径的内容。") @PutMapping(value = "/update") public Result update(@Valid @RequestBody LifePathUpdateRequest request) { LifePathResponse path = lifePathService.updatePath(request); if (path == null) { return Result.error("更新失败"); } return Result.success(path); } /** * 删除实现路径 */ @Operation(summary = "删除实现路径", description = "删除指定的实现路径。") @DeleteMapping(value = "/delete") public Result delete(@Parameter(description = "路径 ID") @RequestParam String id) { boolean deleted = lifePathService.deletePath(id); if (!deleted) { return Result.error("删除失败"); } return Result.success(); } }