refactor: 重命名 backend-single 目录为 server
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.EpicScriptCreateRequest;
|
||||
import com.emotion.dto.request.EpicScriptInspirationRequest;
|
||||
import com.emotion.dto.request.EpicScriptPageRequest;
|
||||
import com.emotion.dto.request.EpicScriptUpdateRequest;
|
||||
import com.emotion.dto.response.EpicScriptInspirationResponse;
|
||||
import com.emotion.dto.response.EpicScriptResponse;
|
||||
import com.emotion.dto.response.InspirationSuggestionResponse;
|
||||
import com.emotion.service.EpicScriptService;
|
||||
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("/epicScript")
|
||||
@Tag(name = "爽文剧本管理", description = "爽文剧本的查询、创建、更新、删除和灵感推荐接口")
|
||||
public class EpicScriptController {
|
||||
|
||||
@Autowired
|
||||
private EpicScriptService epicScriptService;
|
||||
|
||||
/**
|
||||
* 分页查询当前用户的爽文剧本
|
||||
*/
|
||||
@Operation(summary = "分页查询爽文剧本", description = "分页查询当前用户的爽文剧本列表。")
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<EpicScriptResponse>> getPage(@Validated EpicScriptPageRequest request) {
|
||||
PageResult<EpicScriptResponse> pageResult = epicScriptService.getPageByCurrentUser(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的所有爽文剧本列表
|
||||
*/
|
||||
@Operation(summary = "获取爽文剧本列表", description = "获取当前用户的所有爽文剧本列表。")
|
||||
@GetMapping(value = "/listAll")
|
||||
public Result<List<EpicScriptResponse>> getList() {
|
||||
List<EpicScriptResponse> scripts = epicScriptService.getListByCurrentUser();
|
||||
return Result.success(scripts);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取灵感推荐", description = "获取系统推荐的灵感建议列表。")
|
||||
@GetMapping(value = "/inspiration/recommendations")
|
||||
public Result<List<InspirationSuggestionResponse>> getInspirationRecommendations() {
|
||||
return Result.success(epicScriptService.getInspirationRecommendations());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取随机灵感", description = "随机获取指定数量的灵感建议。")
|
||||
@GetMapping(value = "/inspiration/random")
|
||||
public Result<List<InspirationSuggestionResponse>> getRandomInspirations(
|
||||
@Parameter(description = "灵感数量") @RequestParam(required = false, defaultValue = "3") Integer size) {
|
||||
return Result.success(epicScriptService.getRandomInspirations(size));
|
||||
}
|
||||
|
||||
@Operation(summary = "从灵感生成剧本", description = "基于选定的灵感建议生成爽文剧本。")
|
||||
@PostMapping(value = "/inspiration/generate")
|
||||
public Result<EpicScriptInspirationResponse> generateFromInspiration(
|
||||
@Valid @RequestBody EpicScriptInspirationRequest request) {
|
||||
EpicScriptInspirationResponse response;
|
||||
try {
|
||||
response = epicScriptService.generateFromInspiration(request);
|
||||
} catch (IllegalStateException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
if (response == null) {
|
||||
return Result.error("灵感剧本生成失败");
|
||||
}
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取爽文剧本详情
|
||||
*/
|
||||
@Operation(summary = "获取剧本详情", description = "根据 ID 获取爽文剧本的详细信息。")
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<EpicScriptResponse> getById(@Parameter(description = "剧本 ID") @RequestParam String id) {
|
||||
EpicScriptResponse script = epicScriptService.getScriptById(id);
|
||||
if (script == null) {
|
||||
return Result.notFound("爽文剧本不存在");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建爽文剧本
|
||||
*/
|
||||
@Operation(summary = "创建爽文剧本", description = "创建一个新的爽文剧本。")
|
||||
@PostMapping(value = "/create")
|
||||
public Result<EpicScriptResponse> create(@Valid @RequestBody EpicScriptCreateRequest request) {
|
||||
EpicScriptResponse script = epicScriptService.createScript(request);
|
||||
if (script == null) {
|
||||
return Result.error("创建失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新爽文剧本
|
||||
*/
|
||||
@Operation(summary = "更新爽文剧本", description = "修改已有爽文剧本的内容。")
|
||||
@PutMapping(value = "/update")
|
||||
public Result<EpicScriptResponse> update(@Valid @RequestBody EpicScriptUpdateRequest request) {
|
||||
EpicScriptResponse script = epicScriptService.updateScript(request);
|
||||
if (script == null) {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中剧本(取消其他选中状态)
|
||||
*/
|
||||
@Operation(summary = "选中剧本", description = "选中指定剧本并取消其他剧本的选中状态。")
|
||||
@PutMapping(value = "/select")
|
||||
public Result<EpicScriptResponse> select(@Parameter(description = "剧本 ID") @RequestParam String id) {
|
||||
EpicScriptResponse script = epicScriptService.selectScript(id);
|
||||
if (script == null) {
|
||||
return Result.error("选中失败");
|
||||
}
|
||||
return Result.success(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除爽文剧本
|
||||
*/
|
||||
@Operation(summary = "删除爽文剧本", description = "删除指定的爽文剧本。")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@Parameter(description = "剧本 ID") @RequestParam String id) {
|
||||
boolean deleted = epicScriptService.deleteScript(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user