feat: add notification infrastructure with database channel, enum, and notification classes (Story 3.1)
Set up Laravel notification system with NotificationType enum (5 types), NudgeNotification, DocumentUploadedNotification, and DeclarationOverdueNotification classes with database + mail channels. Add email templates, infrastructure tests, and fix existing NotificationController tests for workspace compatibility. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
34
app/Enums/NotificationType.php
Normal file
34
app/Enums/NotificationType.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
final class NotificationType extends Enum
|
||||
{
|
||||
const Nudge = 'nudge';
|
||||
|
||||
const DeclarationOverdue = 'declaration_overdue';
|
||||
|
||||
const DocumentUploaded = 'document_uploaded';
|
||||
|
||||
const BulkNotification = 'bulk_notification';
|
||||
|
||||
const StatusChanged = 'status_changed';
|
||||
|
||||
/**
|
||||
* Get French display labels for each notification type.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
self::Nudge => 'Relance',
|
||||
self::DeclarationOverdue => 'Déclaration en retard',
|
||||
self::DocumentUploaded => 'Document téléversé',
|
||||
self::BulkNotification => 'Notification groupée',
|
||||
self::StatusChanged => 'Statut modifié',
|
||||
];
|
||||
}
|
||||
}
|
||||
43
app/Mail/NudgeNotificationMail.php
Normal file
43
app/Mail/NudgeNotificationMail.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Declaration;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NudgeNotificationMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public Declaration $declaration,
|
||||
public User $sender,
|
||||
) {}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Relance - '.($this->declaration->title ?? 'Sans titre'),
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.nudge-notification',
|
||||
with: [
|
||||
'senderName' => $this->sender->name,
|
||||
'clientName' => $this->declaration->client?->name,
|
||||
'declarationType' => $this->declaration->type?->value,
|
||||
'dueDate' => $this->declaration->due_date?->format('d/m/Y'),
|
||||
'url' => route('declarations.show', $this->declaration),
|
||||
'firmName' => $this->declaration->workspace?->name,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
56
app/Notifications/DeclarationOverdueNotification.php
Normal file
56
app/Notifications/DeclarationOverdueNotification.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use App\Models\Declaration;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class DeclarationOverdueNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 3;
|
||||
|
||||
public int $backoff = 60;
|
||||
|
||||
public bool $deleteWhenMissingModels = true;
|
||||
|
||||
public function __construct(
|
||||
public Declaration $declaration,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'workspace_id' => $this->declaration->workspace_id,
|
||||
'declaration_id' => $this->declaration->id,
|
||||
'notification_type' => NotificationType::DeclarationOverdue,
|
||||
];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('Déclaration en retard - '.($this->declaration->title ?? 'Sans titre'))
|
||||
->markdown('emails.declaration-overdue', [
|
||||
'declarationTitle' => $this->declaration->title ?? 'Sans titre',
|
||||
'dueDate' => $this->declaration->due_date?->format('d/m/Y'),
|
||||
'url' => route('declarations.show', $this->declaration),
|
||||
]);
|
||||
}
|
||||
}
|
||||
42
app/Notifications/DocumentUploadedNotification.php
Normal file
42
app/Notifications/DocumentUploadedNotification.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use App\Models\Declaration;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class DocumentUploadedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public bool $deleteWhenMissingModels = true;
|
||||
|
||||
public function __construct(
|
||||
public Declaration $declaration,
|
||||
public int $clientId,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'workspace_id' => $this->declaration->workspace_id,
|
||||
'declaration_id' => $this->declaration->id,
|
||||
'client_id' => $this->clientId,
|
||||
'notification_type' => NotificationType::DocumentUploaded,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
app/Notifications/NudgeNotification.php
Normal file
53
app/Notifications/NudgeNotification.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use App\Mail\NudgeNotificationMail;
|
||||
use App\Models\Declaration;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class NudgeNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $tries = 3;
|
||||
|
||||
public int $backoff = 60;
|
||||
|
||||
public bool $deleteWhenMissingModels = true;
|
||||
|
||||
public function __construct(
|
||||
public Declaration $declaration,
|
||||
public User $sender,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['database', 'mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toDatabase(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'workspace_id' => $this->declaration->workspace_id,
|
||||
'declaration_id' => $this->declaration->id,
|
||||
'sender_id' => $this->sender->id,
|
||||
'notification_type' => NotificationType::Nudge,
|
||||
];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): NudgeNotificationMail
|
||||
{
|
||||
return new NudgeNotificationMail($this->declaration, $this->sender);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user