浏览代码

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 周之前
父节点
当前提交
38f1ffc4e9
共有 3 个文件被更改,包括 52 次插入2 次删除
  1. 7 0
      app/Http/Controllers/DashboardController.php
  2. 38 0
      app/Services/DashboardService.php
  3. 7 2
      routes/authRoutes/dashboard.php

+ 7 - 0
app/Http/Controllers/DashboardController.php

@@ -14,4 +14,11 @@ class DashboardController extends Controller
         $stats = $this->service->getStats();
         return $this->successResponse(payload: $stats);
     }
+
+    public function partnerStats(): JsonResponse
+    {
+        $stats = $this->service->getPartnerStats();
+
+        return $this->successResponse(payload: $stats);
+    }
 }

+ 38 - 0
app/Services/DashboardService.php

@@ -6,6 +6,8 @@ use App\Enums\UserStatusEnum;
 use App\Enums\UserTypeEnum;
 use App\Models\PartnerAgreement;
 use App\Models\User;
+use App\Models\Appointment;
+use Illuminate\Support\Facades\Auth;
 
 class DashboardService
 {
@@ -22,4 +24,40 @@ class DashboardService
       'associados_pendentes' => User::where('type', UserTypeEnum::ASSOCIADO)->where('status', UserStatusEnum::PENDING)->count(),
     ];
   }
+
+  public function getPartnerStats(): array
+  {
+    // $partnerAgreementId = Auth::user()->partner_agreement_id;
+
+    $partnerAgreementId = 1;
+    return [
+      'authorization' => Appointment::where('partner_agreement_id', $partnerAgreementId)
+        ->where('status', 'pendente')
+        ->count(),
+
+
+      'scheduling' => Appointment::query()
+        ->leftJoin(
+          'partner_agreement_services',
+          'partner_agreement_services.id',
+          '=',
+          'appointments.partner_agreement_service_id'
+        )
+        ->where('appointments.partner_agreement_id', $partnerAgreementId)
+        ->where('partner_agreement_services.requires_scheduling', true)
+         ->where('appointments.status', 'pendente')
+        ->count(),
+
+
+      //aqui  e o count total sem status e sem nada
+      'completed' => Appointment::where('partner_agreement_id', $partnerAgreementId)
+        ->count(),
+
+
+      //status recusado
+      'not_authorized' => Appointment::where('partner_agreement_id', $partnerAgreementId)
+        ->where('status', 'recusado')
+        ->count(),
+    ];
+  }
 }

+ 7 - 2
routes/authRoutes/dashboard.php

@@ -3,6 +3,11 @@
 use App\Http\Controllers\DashboardController;
 use Illuminate\Support\Facades\Route;
 
-Route::controller(DashboardController::class)->prefix('dashboard')->group(function () {
-    Route::get('/stats', 'stats')->middleware('permission:dashboard,view');
+Route::prefix('dashboard')->group(function () {
+
+    Route::get('/stats', [DashboardController::class, 'stats'])->middleware('permission:dashboard,view');
+
+    Route::get('/partner', [DashboardController::class, 'partnerStats'])->middleware('permission:dashboard,view');
+
 });
+