From a0fe5e5c44664d2ea2985d395057b7811454e6e2 Mon Sep 17 00:00:00 2001 From: ArdianS18 Date: Wed, 13 Nov 2024 15:42:32 +0700 Subject: [PATCH] api untuk detail student --- app/Contracts/Interfaces/StudentRepairInterface.php | 1 + .../Interfaces/StudentViolationInterface.php | 1 + .../Repositories/StudentRepairRepository.php | 8 ++++++++ .../Repositories/StudentViolationRepository.php | 9 +++++++++ app/Http/Controllers/Api/StudentApiController.php | 11 +++++++++++ routes/api.php | 1 + 6 files changed, 31 insertions(+) diff --git a/app/Contracts/Interfaces/StudentRepairInterface.php b/app/Contracts/Interfaces/StudentRepairInterface.php index a3c8f508..51c6f426 100644 --- a/app/Contracts/Interfaces/StudentRepairInterface.php +++ b/app/Contracts/Interfaces/StudentRepairInterface.php @@ -19,4 +19,5 @@ public function groubByCreated(mixed $id): mixed; public function countByStudent(): mixed; public function count_approved(mixed $query): mixed; public function groupByClassroomStudentAndCreated(): mixed; + public function count_repair(mixed $id): mixed; } diff --git a/app/Contracts/Interfaces/StudentViolationInterface.php b/app/Contracts/Interfaces/StudentViolationInterface.php index 4e83684d..f5b502a8 100644 --- a/app/Contracts/Interfaces/StudentViolationInterface.php +++ b/app/Contracts/Interfaces/StudentViolationInterface.php @@ -18,4 +18,5 @@ public function groubByCreated(mixed $id) : mixed; public function ViolationChart(mixed $year, mixed $month): mixed; public function count(mixed $query): mixed; public function countByStudent(): mixed; + public function count_violation(mixed $id): mixed; } diff --git a/app/Contracts/Repositories/StudentRepairRepository.php b/app/Contracts/Repositories/StudentRepairRepository.php index d6b74381..1fa4b80d 100644 --- a/app/Contracts/Repositories/StudentRepairRepository.php +++ b/app/Contracts/Repositories/StudentRepairRepository.php @@ -119,4 +119,12 @@ public function groupByClassroomStudentAndCreated(): mixed return $group->groupBy('classroom_student_id'); }); } + + public function count_repair(mixed $id): mixed + { + return $this->model->query() + ->whereRelation('classroomStudent', 'student_id', $id) + ->where('is_approved', '1') + ->count(); + } } diff --git a/app/Contracts/Repositories/StudentViolationRepository.php b/app/Contracts/Repositories/StudentViolationRepository.php index 785c84ef..b748acb8 100644 --- a/app/Contracts/Repositories/StudentViolationRepository.php +++ b/app/Contracts/Repositories/StudentViolationRepository.php @@ -126,4 +126,13 @@ public function count(mixed $query): mixed return $result->count(); } + + public function count_violation(mixed $id): mixed + { + return $this->model->query() + ->whereRelation('classroomStudent', 'student_id', $id) + ->get() + ->groupBy('regulation_id') + ->count(); + } } diff --git a/app/Http/Controllers/Api/StudentApiController.php b/app/Http/Controllers/Api/StudentApiController.php index bd0dc9fe..948c777d 100644 --- a/app/Http/Controllers/Api/StudentApiController.php +++ b/app/Http/Controllers/Api/StudentApiController.php @@ -157,4 +157,15 @@ public function point_student(User $user) $student = $this->student->whereUserId($user->id); return response()->json(['status' => 'success', 'message' => "Berhasil mengirim bukti perbaikan",'code' => 200, 'point' => $student->point]); } + + public function get_detail_profile(User $user) + { + $student = $this->student->whereUserId($user->id); + $repairs = $this->studentRepair->count_repair($student->id); + $violations = $this->studentViolation->count_violation($student->id); + return response()->json(['status' => 'success', 'message' => "Berhasil mengirim bukti perbaikan",'code' => 200, 'data' => [ + 'repair' => $repairs, + 'violation' => $violations, + ]]); + } } diff --git a/routes/api.php b/routes/api.php index f38d336a..a9a1041d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -74,6 +74,7 @@ Route::get('student/lesson-schedule/{user}', [StudentApiController::class, 'lessonSchedule']); Route::get('student/class-student/{user}', [StudentApiController::class, 'class_student']); Route::get('student/point-student/{user}', [StudentApiController::class, 'point_student']); +Route::get('student/detail-profile/{user}', [StudentApiController::class, 'get_detail_profile']); Route::get('feedback-active', [PermissionController::class, 'is_active']); Route::get('student/violation/{user}', [StudentApiController::class, 'violation']);