feat: add guest notification center

This commit is contained in:
Codex Agent
2025-11-12 16:56:50 +01:00
parent 062932ce38
commit 4495ac1895
27 changed files with 2042 additions and 64 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace Database\Factories;
use App\Enums\GuestNotificationAudience;
use App\Enums\GuestNotificationState;
use App\Enums\GuestNotificationType;
use App\Models\Event;
use App\Models\GuestNotification;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<GuestNotification>
*/
class GuestNotificationFactory extends Factory
{
protected $model = GuestNotification::class;
public function definition(): array
{
$tenantFactory = Tenant::factory();
return [
'tenant_id' => $tenantFactory,
'event_id' => Event::factory()->for($tenantFactory),
'type' => GuestNotificationType::BROADCAST,
'title' => $this->faker->sentence(4),
'body' => $this->faker->sentences(2, true),
'payload' => null,
'audience_scope' => GuestNotificationAudience::ALL,
'target_identifier' => null,
'status' => GuestNotificationState::ACTIVE,
'priority' => 0,
'expires_at' => null,
];
}
public function guestTarget(string $identifier): self
{
return $this->state(fn () => [
'audience_scope' => GuestNotificationAudience::GUEST,
'target_identifier' => $identifier,
]);
}
public function system(GuestNotificationType $type): self
{
return $this->state(fn () => ['type' => $type]);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace Database\Factories;
use App\Enums\GuestNotificationDeliveryStatus;
use App\Models\GuestNotification;
use App\Models\GuestNotificationReceipt;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<GuestNotificationReceipt>
*/
class GuestNotificationReceiptFactory extends Factory
{
protected $model = GuestNotificationReceipt::class;
public function definition(): array
{
return [
'guest_notification_id' => GuestNotification::factory(),
'guest_identifier' => $this->faker->unique()->userName(),
'status' => GuestNotificationDeliveryStatus::NEW,
'read_at' => null,
'dismissed_at' => null,
];
}
public function read(): self
{
return $this->state(fn () => [
'status' => GuestNotificationDeliveryStatus::READ,
'read_at' => now(),
]);
}
public function dismissed(): self
{
return $this->state(fn () => [
'status' => GuestNotificationDeliveryStatus::DISMISSED,
'dismissed_at' => now(),
]);
}
}

View File

@@ -0,0 +1,50 @@
<?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('guest_notifications', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
$table->foreignId('event_id')->constrained()->cascadeOnDelete();
$table->string('type', 64);
$table->string('title', 160);
$table->text('body')->nullable();
$table->json('payload')->nullable();
$table->string('audience_scope', 32)->default('all');
$table->string('target_identifier', 120)->nullable();
$table->string('status', 32)->default('active');
$table->unsignedTinyInteger('priority')->default(0);
$table->timestamp('expires_at')->nullable();
$table->timestamps();
$table->index(['event_id', 'audience_scope']);
$table->index(['event_id', 'status']);
$table->index(['event_id', 'created_at']);
});
Schema::create('guest_notification_receipts', function (Blueprint $table) {
$table->id();
$table->foreignId('guest_notification_id')->constrained()->cascadeOnDelete();
$table->string('guest_identifier', 120);
$table->string('status', 32)->default('new');
$table->timestamp('read_at')->nullable();
$table->timestamp('dismissed_at')->nullable();
$table->timestamps();
$table->unique(['guest_notification_id', 'guest_identifier']);
$table->index(['guest_identifier', 'status']);
});
}
public function down(): void
{
Schema::dropIfExists('guest_notification_receipts');
Schema::dropIfExists('guest_notifications');
}
};