소스 검색

Merge branch 'feature/SERPRATI-GUS-plataforma-v1' of gogs.softpar.inf.br:Softpar/sfp_api_laravel_serprati into feature/SERPRATI-GUS-plataforma-v1

Gustavo Zanatta 3 주 전
부모
커밋
1c332abfd8

+ 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());

+ 1 - 0
app/Http/Resources/StoreItemResource.php

@@ -21,6 +21,7 @@ class StoreItemResource extends JsonResource
             'supplier_price'  => $this->supplier_price,
             'status'          => $this->status,
             'interests_count' => $this->interests_count ?? 0,
+            'user_interested' => (bool) ($this->user_interested ?? false),
             'variations'      => $this->whenLoaded('variations', fn() => StoreItemVariationResource::collection($this->variations)),
             'media'           => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
             'created_at'      => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),

+ 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)

+ 13 - 1
app/Services/StoreItemService.php

@@ -12,14 +12,26 @@ use Illuminate\Support\Facades\DB;
 
 class StoreItemService
 {
+
     public function getAll(): Collection
     {
+        $userId = Auth::id();
+
         return StoreItem::with(['category', 'media', 'variations'])
             ->withCount('interests')
+            ->withCount([
+                'interests as user_interested' => fn($q) =>
+                $q->where('user_id', $userId)
+            ])
             ->orderBy('name')
-            ->get();
+            ->get()
+            ->map(function ($item) {
+                $item->user_interested = $item->user_interested > 0;
+                return $item;
+            });
     }
 
+
     public function findById(int $id): ?StoreItem
     {
         return StoreItem::with(['category', 'media', 'variations'])->find($id);

+ 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 - 0
database/seeders/UserTypePermissionSeeder.php

@@ -42,6 +42,7 @@ class UserTypePermissionSeeder extends Seeder
                         ['scope' => 'config.user',            'bits' => Permission::VIEW | Permission::EDIT],
                         ['scope' => 'parceiro.convenio',      'bits' => Permission::VIEW],
                         ['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],
@@ -49,6 +50,7 @@ class UserTypePermissionSeeder extends Seeder
                     ];
                     break;
 
+
                 case UserTypeEnum::PARCEIRO:
                     $dataToSync = [
                         ['scope' => 'dashboard',            'bits' => Permission::VIEW | Permission::MENU],

+ 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');