ソースを参照

feat: :sparkles: feat(notificação chamativa) Esta sendo inplementando o modulo de notificação chamativa para agendamento direto

Foi iniciada a implementação do módulo de notificações push para agendamentos diretos. Foram realizados os ajustes iniciais no backend para integração com o serviço de Push Notification, criação da estrutura da nova notificação e preparação do fluxo de envio ao prestador.

fase:dev | origin:escopo
kayo henrique 1 週間 前
コミット
1bfeab83a7

+ 1 - 0
app/Enums/PushNotificationCategoryEnum.php

@@ -12,4 +12,5 @@ enum PushNotificationCategoryEnum: string
     case EDUCATIVO_CONVERSAO  = 'educativo_conversao';
     case SOCIAL_PROOF         = 'social_proof';
     case CONTEXTUAL           = 'contextual';
+    case AGENDA               = 'agenda';
 }

+ 2 - 0
app/Http/Controllers/DeviceTokenController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\Http\Requests\DeviceTokenRequest;
 use App\Services\DeviceTokenService;
 use Illuminate\Http\JsonResponse;
+use Illuminate\Support\Facades\Log;
 
 class DeviceTokenController extends Controller
 {
@@ -12,6 +13,7 @@ class DeviceTokenController extends Controller
 
     public function store(DeviceTokenRequest $request): JsonResponse
     {
+        Log::info('=== DEVICE TOKEN RECEBIDO ===', $request->validated());
         $this->deviceTokenService->register($request->validated());
 
         return $this->successResponse(code: 201);

+ 60 - 0
app/Notifications/Push/Prestador/Agendamento/NewPushRequest.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace App\Notifications\Push\Prestador\Agendamento;
+
+use App\Enums\PushNotificationCategoryEnum;
+use App\Enums\PushNotificationTargetEnum;
+use App\Notifications\Push\BasePushNotification;
+use Illuminate\Database\Eloquent\Collection;
+
+/**
+ * Notificação enviada quando um cliente cria
+ * um agendamento direto para um prestador.
+ */
+class NewPushRequest extends BasePushNotification
+{
+    public function __construct(
+        private readonly string $clientName,
+    ) {}
+
+    public function label(): string
+    {
+        return 'provider_new_schedule_request';
+    }
+
+    public function title(): string
+    {
+        return 'Nova solicitação';
+    }
+
+    public function body(): string
+    {
+        return "{$this->clientName} solicitou um novo agendamento.";
+    }
+
+    public function target(): PushNotificationTargetEnum
+    {
+        return PushNotificationTargetEnum::PRESTADOR;
+    }
+
+    public function category(): PushNotificationCategoryEnum
+    {
+        return PushNotificationCategoryEnum::AGENDA;
+    }
+
+    public function eligibleUsers(): Collection
+    {
+        // Não utilizado para notificações transacionais.
+        return new Collection();
+    }
+
+    public function notificationCooldownDays(): int
+    {
+        return 0;
+    }
+
+    public function categoryCooldownDays(): int
+    {
+        return 0;
+    }
+}

+ 11 - 1
app/Services/ScheduleService.php

@@ -10,6 +10,8 @@ use App\Models\Provider;
 use App\Models\Schedule;
 use App\Rules\ScheduleBusinessRules;
 use App\Services\NotificationService;
+use App\Services\PushNotificationService;
+use App\Notifications\Push\Prestador\Agendamento\NewPushRequest;
 use Carbon\Carbon;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
@@ -78,8 +80,16 @@ class ScheduleService
                         'type'        => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION->value,
                         'user_id'     => $newSchedule->provider->user_id,
                     ]);
+                    // Push Notification
+                    $pushNotificationService = app(PushNotificationService::class);
+
+                    $pushNotificationService->sendToUser(
+                        $newSchedule->provider->user,
+                        new NewPushRequest($newSchedule->client->user->name)
+                    );
                 }
 
+
                 $createdSchedules[] = $newSchedule;
             }
 
@@ -508,7 +518,7 @@ class ScheduleService
         } catch (\Exception $e) {
             DB::rollBack();
 
-            Log::error('Erro ao cancelar agendamento: '.$e->getMessage());
+            Log::error('Erro ao cancelar agendamento: ' . $e->getMessage());
 
             throw $e;
         }