add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Notifications;
|
||||
|
||||
use App\Models\Notification;
|
||||
|
||||
class NotificationManagementService
|
||||
{
|
||||
public function update(int $notificationId, array $payload): array
|
||||
{
|
||||
$notification = Notification::query()->find($notificationId);
|
||||
if (!$notification) {
|
||||
return ['ok' => false, 'message' => 'Notification not found.'];
|
||||
}
|
||||
|
||||
$notification->update([
|
||||
'title' => $payload['title'] ?? $notification->title,
|
||||
'message' => $payload['message'] ?? $notification->message,
|
||||
'target_group' => $payload['target_group'] ?? $notification->target_group,
|
||||
'delivery_channels' => $payload['channels'] ?? $notification->delivery_channels,
|
||||
'priority' => $payload['priority'] ?? $notification->priority,
|
||||
'status' => $payload['status'] ?? $notification->status,
|
||||
'action_url' => $payload['action_url'] ?? $notification->action_url,
|
||||
'attachment_path' => $payload['attachment_path'] ?? $notification->attachment_path,
|
||||
'scheduled_at' => $payload['scheduled_at'] ?? $notification->scheduled_at,
|
||||
'expires_at' => $payload['expires_at'] ?? $notification->expires_at,
|
||||
'updated_at' => utc_now(),
|
||||
]);
|
||||
|
||||
return ['ok' => true, 'notification' => $notification];
|
||||
}
|
||||
|
||||
public function delete(int $notificationId): bool
|
||||
{
|
||||
$notification = Notification::query()->find($notificationId);
|
||||
if (!$notification) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $notification->delete();
|
||||
}
|
||||
|
||||
public function restore(int $notificationId): bool
|
||||
{
|
||||
return Notification::restoreNotification($notificationId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user