Procházet zdrojové kódy

feat: :sparkles: feat (plataforma-v1) Foi criado um metedo novo para notificações

Criação de método e rota para listagem de notificações do usuário autenticado, realizando o envio e exibição das notificações de acordo com tipo de usuário, setor e cargo.

fase:dev | origin:escopo
kayo henrique před 3 týdny
rodič
revize
bb9a49ed57

+ 11 - 0
app/Http/Controllers/NotificationController.php

@@ -61,6 +61,17 @@ class NotificationController extends Controller
         return $this->successResponse(payload: NotificationSendResource::collection($items));
     }
 
+    public function myNotifications(): JsonResponse
+    {
+        $items = $this->service->getByUser(Auth::id());
+
+        return $this->successResponse(
+            payload: NotificationSendResource::collection($items)
+        );
+    }
+
+
+
     public function markAsRead(int $sendId): JsonResponse
     {
         $this->service->markAsRead($sendId, Auth::id());

+ 12 - 0
app/Services/NotificationService.php

@@ -71,6 +71,18 @@ class NotificationService
             ->get();
     }
 
+    public function getByUser(int $userId): Collection
+    {
+        return NotificationSend::with([
+            'notification',
+            'notification.media',
+        ])
+            ->where('user_id', $userId)
+            ->orderBy('created_at', 'desc')
+            ->get();
+    }
+
+
     public function markAsRead(int $sendId, int $userId): bool
     {
         $send = NotificationSend::where('id', $sendId)

+ 7 - 0
database/seeders/PermissionSeeder.php

@@ -173,6 +173,13 @@ class PermissionSeeder extends Seeder
                         "bits" => Permission::CRUD,
                         "children" => [],
                     ],
+
+                    [
+                       "scope" => "associado.loja",
+                        "description" => "Loja do Associado",
+                        "bits" => Permission::VIEW,
+                        "children" => [], 
+                    ]
                 ],
             ],
             [

+ 2 - 1
database/seeders/UserTypePermissionSeeder.php

@@ -41,7 +41,8 @@ class UserTypePermissionSeeder extends Seeder
                         ['scope' => 'agendamento',            'bits' => Permission::VIEW | Permission::ADD | Permission::EDIT],
                         ['scope' => 'config.user',            'bits' => Permission::VIEW | Permission::EDIT],
                         ['scope' => 'parceiro.convenio',      'bits' => Permission::VIEW],
-                        ['scope' => 'loja.item',              'bits' => Permission::VIEW | Permission::MENU],
+                        ['scope' => 'loja.item',              'bits' => Permission::VIEW],
+                        ['scope' => 'associado.loja', 'bits' => Permission::VIEW | Permission::MENU ],
                         ['scope' => 'categoria',              'bits' => Permission::VIEW],
                         ['scope' => 'config.position',        'bits' => Permission::VIEW],
                         ['scope' => 'config.sector',          'bits' => Permission::VIEW],

+ 2 - 0
routes/authRoutes/notification.php

@@ -10,6 +10,8 @@ Route::controller(NotificationController::class)->prefix('notification')->group(
 
     Route::post('/', 'store')->middleware('permission:notificacao,add');
 
+    Route::get('/my', 'myNotifications')->middleware('permission:notificacao,view');
+
     Route::get('/my/unread', 'myUnread')->middleware('permission:notificacao,view');
 
     Route::patch('/{sendId}/read', 'markAsRead')->middleware('permission:notificacao,view');