refactor: 重命名 backend-single 目录为 server
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.PageResult;
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.dto.request.MessageCreateRequest;
|
||||
import com.emotion.dto.request.MessagePageRequest;
|
||||
import com.emotion.dto.request.MessageSearchRequest;
|
||||
import com.emotion.dto.request.MessageRecentRequest;
|
||||
import com.emotion.dto.response.MessageResponse;
|
||||
import com.emotion.service.MessageService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* 消息控制器
|
||||
*
|
||||
* @author huazhongmin
|
||||
* @date 2025-09-08
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/message")
|
||||
@Slf4j
|
||||
@Tag(name = "消息管理", description = "会话消息的查询、创建、搜索、更新和删除接口")
|
||||
public class MessageController {
|
||||
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
|
||||
/**
|
||||
* 创建消息
|
||||
*/
|
||||
@Operation(summary = "创建消息", description = "在指定会话中创建一条新消息。")
|
||||
@PostMapping(value = "/create")
|
||||
public Result<MessageResponse> create(@Valid @RequestBody MessageCreateRequest request) {
|
||||
MessageResponse response = messageService.createMessageFromRequest(request);
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取消息
|
||||
*/
|
||||
@Operation(summary = "获取消息详情", description = "根据 ID 获取消息的详细信息。")
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<MessageResponse> getById(@Parameter(description = "消息 ID") @RequestParam String id) {
|
||||
MessageResponse response = messageService.getMessageById(id);
|
||||
if (response == null) {
|
||||
return Result.notFound("消息不存在");
|
||||
}
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询消息
|
||||
*/
|
||||
@Operation(summary = "分页查询消息", description = "分页查询指定会话的消息列表。")
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<MessageResponse>> getPage(@Validated MessagePageRequest request) {
|
||||
PageResult<MessageResponse> pageResult = messageService.getPageWithResponse(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索消息
|
||||
*/
|
||||
@Operation(summary = "搜索消息", description = "根据关键词在指定会话中搜索消息内容。")
|
||||
@PostMapping(value = "/search")
|
||||
public Result<PageResult<MessageResponse>> search(@Valid @RequestBody MessageSearchRequest request) {
|
||||
PageResult<MessageResponse> pageResult = messageService.searchWithResponse(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的消息
|
||||
*/
|
||||
@Operation(summary = "获取最近消息", description = "获取指定会话最近的消息列表。")
|
||||
@PostMapping(value = "/recent")
|
||||
public Result<PageResult<MessageResponse>> getRecentMessages(@Valid @RequestBody MessageRecentRequest request) {
|
||||
PageResult<MessageResponse> pageResult = messageService.getRecentWithResponse(request);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新消息
|
||||
*/
|
||||
@Operation(summary = "更新消息", description = "修改指定消息的内容。")
|
||||
@PutMapping(value = "/update")
|
||||
public Result<MessageResponse> update(@RequestParam String id, @RequestParam String content) {
|
||||
MessageResponse response = messageService.updateMessage(id, content);
|
||||
if (response == null) {
|
||||
return Result.notFound("消息不存在");
|
||||
}
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除消息
|
||||
*/
|
||||
@Operation(summary = "删除消息", description = "删除指定的消息记录。")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@Parameter(description = "消息 ID") @RequestParam String id) {
|
||||
boolean deleted = messageService.deleteMessage(id);
|
||||
if (!deleted) {
|
||||
return Result.error("删除失败");
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user