main: 增强会话功能,支持消息管理和接口文档

- 添加 `last_message_id` 字段至 `chat_sessions` 表,更新其关联索引
- 实现会话更新接口,支持修改名称与状态并添加验证逻辑
- 增加会话列表接口,支持状态过滤与关键字查询
- 提供会话和消息相关的资源类和请求验证类
- 扩展 `ChatService` 服务层逻辑以处理会话更新和消息附加
- 编写测试用例以验证新功能的正确性
- 增加接口文档及 OpenAPI 规范文件,覆盖新增功能
- 更新数据库播种器,添加默认用户
This commit is contained in:
2025-12-14 20:20:27 +08:00
parent c6d6534b63
commit 6356baacc0
14 changed files with 852 additions and 4 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Str;
/** @mixin \App\Models\ChatSession */
class ChatSessionResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$preview = $this->last_message_content ?? '';
return [
'session_id' => $this->session_id,
'session_name' => $this->session_name,
'status' => $this->status,
'last_seq' => $this->last_seq,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'last_message_at' => $this->last_message_at,
'last_message_preview' => $preview ? Str::limit($preview, 120) : '',
'last_message_role' => $this->last_message_role,
'last_message_type' => $this->last_message_type,
];
}
}