소스 검색

feat(student-summary): enhance summary response to include student counts by status

alvesantos 4 일 전
부모
커밋
20ba5703b8
2개의 변경된 파일16개의 추가작업 그리고 1개의 파일을 삭제
  1. 8 0
      app/Http/Controllers/FranchiseeDashboardController.php
  2. 8 1
      app/Services/StudentService.php

+ 8 - 0
app/Http/Controllers/FranchiseeDashboardController.php

@@ -20,8 +20,16 @@ public function summary(): JsonResponse
         $contracts = StudentContract::latestVersion()->where('unit_id', $unitId)->get(['id', 'status']);
         $unit = \App\Models\Unit::find($unitId);
 
+        $studentsByStatus = Student::where('unit_id', $unitId)->get(['status']);
+
         return $this->successResponse(payload: [
             'students_count' => $students->count(),
+            'students_by_status' => [
+                'lead' => $studentsByStatus->where('status', Student::STATUS_LEAD)->count(),
+                'active' => $studentsByStatus->where('status', Student::STATUS_ACTIVE)->count(),
+                'ex_student' => $studentsByStatus->where('status', Student::STATUS_EX_STUDENT)->count(),
+                'locked' => $studentsByStatus->where('status', Student::STATUS_LOCKED)->count(),
+            ],
             'unit_config' => [
                 'active_students_min' => $unit->active_students_min ?? 30,
                 'active_students_medium' => $unit->active_students_medium ?? 50,

+ 8 - 1
app/Services/StudentService.php

@@ -175,7 +175,14 @@ public function getFranchisorSummary(array $unitIds = []): array
 
         $active = (clone $query)->where('status', 'active')->count();
 
-        return ['total' => $total, 'active' => $active];
+        $byStatus = [
+            'lead' => (clone $query)->where('status', Student::STATUS_LEAD)->count(),
+            'active' => $active,
+            'ex_student' => (clone $query)->where('status', Student::STATUS_EX_STUDENT)->count(),
+            'locked' => (clone $query)->where('status', Student::STATUS_LOCKED)->count(),
+        ];
+
+        return ['total' => $total, 'active' => $active, 'by_status' => $byStatus];
     }
 
     //