- 添加 `last_message_id` 字段至 `chat_sessions` 表,更新其关联索引 - 实现会话更新接口,支持修改名称与状态并添加验证逻辑 - 增加会话列表接口,支持状态过滤与关键字查询 - 提供会话和消息相关的资源类和请求验证类 - 扩展 `ChatService` 服务层逻辑以处理会话更新和消息附加 - 编写测试用例以验证新功能的正确性 - 增加接口文档及 OpenAPI 规范文件,覆盖新增功能 - 更新数据库播种器,添加默认用户
50 lines
992 B
PHP
50 lines
992 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\ChatSessionStatus;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ChatSession extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $primaryKey = 'session_id';
|
|
|
|
public $incrementing = false;
|
|
|
|
protected $keyType = 'string';
|
|
|
|
protected $fillable = [
|
|
'session_id',
|
|
'session_name',
|
|
'status',
|
|
'last_seq',
|
|
'last_message_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'last_seq' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function messages(): HasMany
|
|
{
|
|
return $this->hasMany(Message::class, 'session_id', 'session_id');
|
|
}
|
|
|
|
public function isClosed(): bool
|
|
{
|
|
return $this->status === ChatSessionStatus::CLOSED;
|
|
}
|
|
|
|
public function isLocked(): bool
|
|
{
|
|
return $this->status === ChatSessionStatus::LOCKED;
|
|
}
|
|
}
|