main: 用户管理和会话功能初始实现

- 添加用户管理功能的测试,包括创建、更新、停用、激活用户及用户登录 JWT 测试
- 提供用户管理相关的请求验证类与控制器
- 引入 CORS 配置信息,支持跨域请求
- 添加数据库播种器以便创建根用户
- 配置 API 默认使用 JWT 认证
- 添加聊天会话和消息的模型、迁移文件及关联功能
This commit is contained in:
2025-12-14 17:49:08 +08:00
parent e28318b4ec
commit c6d6534b63
36 changed files with 2119 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ class UserFactory extends Factory
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'is_active' => true,
];
}

View File

@@ -17,6 +17,7 @@ return new class extends Migration
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->boolean('is_active')->default(true);
$table->rememberToken();
$table->timestamps();
});

View File

@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('chat_sessions', function (Blueprint $table) {
$table->uuid('session_id')->primary();
$table->string('session_name', 255)->nullable();
$table->string('status', 16)->default('OPEN');
$table->unsignedBigInteger('last_seq')->default(0);
$table->timestamps();
});
Schema::create('messages', function (Blueprint $table) {
$table->uuid('message_id')->primary();
$table->uuid('session_id');
$table->string('role', 32);
$table->string('type', 64);
$table->text('content')->nullable();
$table->jsonb('payload')->nullable();
$table->timestamp('created_at')->useCurrent();
$table->unsignedBigInteger('seq');
$table->uuid('reply_to')->nullable();
$table->string('dedupe_key', 128)->nullable();
$table->foreign('session_id')->references('session_id')->on('chat_sessions')->onDelete('cascade');
$table->unique(['session_id', 'seq']);
$table->unique(['session_id', 'dedupe_key']);
$table->index(['session_id', 'seq']);
});
}
public function down(): void
{
Schema::dropIfExists('messages');
Schema::dropIfExists('chat_sessions');
}
};

View File

@@ -5,6 +5,7 @@ namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class DatabaseSeeder extends Seeder
{
@@ -15,11 +16,14 @@ class DatabaseSeeder extends Seeder
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
User::updateOrCreate(
['email' => 'root@example.com'],
[
'name' => 'root',
'password' => Hash::make('Root@123456'),
'is_active' => true,
'email_verified_at' => now(),
],
);
}
}