瀏覽代碼

refatoracao rotas: padronizacao de rotas e permissoes por tipo de usuario

Gustavo Zanatta 3 周之前
父節點
當前提交
a50a3f7624

+ 6 - 0
app/Http/Controllers/AppointmentController.php

@@ -25,6 +25,12 @@ class AppointmentController extends Controller
         return $this->successResponse(payload: AppointmentResource::collection($items));
     }
 
+    public function partnerAppointments(): JsonResponse
+    {
+        $items = $this->service->getAllByPartnerUser(Auth::id());
+        return $this->successResponse(payload: AppointmentResource::collection($items));
+    }
+
     public function store(AppointmentRequest $request): JsonResponse
     {
         $item = $this->service->create($request->validated());

+ 8 - 0
app/Services/AppointmentService.php

@@ -25,6 +25,14 @@ class AppointmentService
             ->get();
     }
 
+    public function getAllByPartnerUser(int $userId): Collection
+    {
+        return Appointment::with(['user', 'partnerAgreement', 'partnerAgreementService'])
+            ->whereHas('partnerAgreement', fn($q) => $q->where('user_id', $userId))
+            ->orderBy('date', 'desc')
+            ->get();
+    }
+
     public function findById(int $id): ?Appointment
     {
         return Appointment::with(['user', 'partnerAgreement', 'partnerAgreementService'])->find($id);

+ 7 - 1
database/seeders/PermissionSeeder.php

@@ -182,8 +182,14 @@ class PermissionSeeder extends Seeder
                     [
                        "scope" => "associado.agendamento",
                         "description" => "Agendamento do Associado",
+                        "bits" => Permission::VIEW | Permission::ADD | Permission::EDIT,
+                        "children" => [],
+                    ],
+                    [
+                        "scope" => "associado.notificacao",
+                        "description" => "Notificações do Associado",
                         "bits" => Permission::VIEW,
-                        "children" => [], 
+                        "children" => [],
                     ]
                 ],
             ],

+ 2 - 7
database/seeders/UserTypePermissionSeeder.php

@@ -37,14 +37,9 @@ class UserTypePermissionSeeder extends Seeder
                         ['scope' => 'associado.carteirinha',  'bits' => Permission::VIEW | Permission::MENU],
                         ['scope' => 'associado.convenio',     'bits' => Permission::VIEW | Permission::MENU],
                         ['scope' => 'associado.dependente',   'bits' => Permission::VIEW | Permission::ADD | Permission::EDIT | Permission::DELETE | Permission::MENU],
-                        ['scope' => 'notificacao',            'bits' => Permission::VIEW | Permission::MENU],
+                        ['scope' => 'associado.notificacao',  'bits' => Permission::VIEW | Permission::MENU],
                         ['scope' => 'associado.agendamento',  'bits' => Permission::VIEW | Permission::ADD | Permission::EDIT | Permission::MENU],
-                        ['scope' => 'agendamento',            'bits' => Permission::VIEW | Permission::ADD | Permission::EDIT | Permission::MENU],
-                        ['scope' => 'config.user',            'bits' => Permission::VIEW | Permission::EDIT],
-                        ['scope' => 'parceiro.convenio',      'bits' => Permission::VIEW],
-                        ['scope' => 'parceiro.servico',       'bits' => Permission::VIEW],
-                        ['scope' => 'loja.item',              'bits' => Permission::VIEW],
-                        ['scope' => 'associado.loja',         'bits' => Permission::VIEW | Permission::MENU ],
+                        ['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],

+ 10 - 0
routes/authRoutes/associado_appointment.php

@@ -0,0 +1,10 @@
+<?php
+
+use App\Http\Controllers\AppointmentController;
+use Illuminate\Support\Facades\Route;
+
+Route::controller(AppointmentController::class)->prefix('associado/appointment')->group(function () {
+    Route::get('/my',    'myAppointments')->middleware('permission:associado.agendamento,view');
+    Route::post('/',     'store')         ->middleware('permission:associado.agendamento,add');
+    Route::put('/{id}',  'update')        ->middleware('permission:associado.agendamento,edit');
+});

+ 10 - 0
routes/authRoutes/associado_notification.php

@@ -0,0 +1,10 @@
+<?php
+
+use App\Http\Controllers\NotificationController;
+use Illuminate\Support\Facades\Route;
+
+Route::controller(NotificationController::class)->prefix('associado/notification')->group(function () {
+    Route::get('/my',              'myNotifications')->middleware('permission:associado.notificacao,view');
+    Route::get('/my/unread',       'myUnread')       ->middleware('permission:associado.notificacao,view');
+    Route::patch('/{sendId}/read', 'markAsRead')     ->middleware('permission:associado.notificacao,view');
+});

+ 18 - 0
routes/authRoutes/associado_partner_agreement.php

@@ -0,0 +1,18 @@
+<?php
+
+use App\Http\Controllers\PartnerAgreementController;
+use App\Http\Controllers\PartnerAgreementServiceController;
+use Illuminate\Support\Facades\Route;
+
+Route::prefix('associado')->group(function () {
+    Route::controller(PartnerAgreementController::class)->prefix('partner-agreement')->group(function () {
+        Route::get('/',        'index')     ->middleware('permission:associado.convenio,view');
+        Route::get('/{id}',    'show')      ->middleware('permission:associado.convenio,view');
+        Route::get('/{id}/dados', 'showDados')->middleware('permission:associado.convenio,view');
+    });
+
+    Route::controller(PartnerAgreementServiceController::class)->prefix('partner-agreement-service')->group(function () {
+        Route::get('/partner/{partnerAgreementId}', 'indexByPartner')->middleware('permission:associado.convenio,view');
+        Route::get('/{id}',                         'show')          ->middleware('permission:associado.convenio,view');
+    });
+});

+ 12 - 0
routes/authRoutes/associado_store.php

@@ -0,0 +1,12 @@
+<?php
+
+use App\Http\Controllers\StoreItemController;
+use Illuminate\Support\Facades\Route;
+
+Route::controller(StoreItemController::class)->prefix('associado/store-item')->group(function () {
+    Route::get('/my/interests',      'myInterests')   ->middleware('permission:associado.loja,view');
+    Route::get('/',                  'index')          ->middleware('permission:associado.loja,view');
+    Route::get('/{id}',              'show')           ->middleware('permission:associado.loja,view');
+    Route::post('/{id}/interest',    'toggleInterest') ->middleware('permission:associado.loja,view');
+    Route::get('/{id}/interests',    'getInterests')   ->middleware('permission:associado.loja,view');
+});

+ 9 - 0
routes/authRoutes/parceiro_appointment.php

@@ -0,0 +1,9 @@
+<?php
+
+use App\Http\Controllers\AppointmentController;
+use Illuminate\Support\Facades\Route;
+
+Route::controller(AppointmentController::class)->prefix('parceiro/appointment')->group(function () {
+    Route::get('/',       'partnerAppointments')->middleware('permission:parceiro.agendamento,view');
+    Route::get('/{id}',   'show')               ->middleware('permission:parceiro.agendamento,view');
+});

+ 10 - 0
routes/authRoutes/parceiro_notification.php

@@ -0,0 +1,10 @@
+<?php
+
+use App\Http\Controllers\NotificationController;
+use Illuminate\Support\Facades\Route;
+
+Route::controller(NotificationController::class)->prefix('parceiro/notification')->group(function () {
+    Route::get('/my',              'myNotifications')->middleware('permission:parceiro.notificacao,view');
+    Route::get('/my/unread',       'myUnread')       ->middleware('permission:parceiro.notificacao,view');
+    Route::patch('/{sendId}/read', 'markAsRead')     ->middleware('permission:parceiro.notificacao,view');
+});