diff --git a/app/Http/Controllers/Api/StafApiController.php b/app/Http/Controllers/Api/StafApiController.php index c986e892..fc6eb9c8 100644 --- a/app/Http/Controllers/Api/StafApiController.php +++ b/app/Http/Controllers/Api/StafApiController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Api; +use App\Contracts\Interfaces\AttendanceInterface; use App\Contracts\Interfaces\AttendanceRuleInterface; use App\Contracts\Interfaces\EmployeeInterface; use App\Contracts\Interfaces\EmployeeJournalInterface; @@ -10,11 +11,13 @@ use App\Contracts\Interfaces\StudentInterface; use App\Contracts\Interfaces\StudentRepairInterface; use App\Contracts\Interfaces\StudentViolationInterface; +use App\Enums\AttendanceEnum; use App\Http\Controllers\Controller; use App\Http\Resources\EmployeeJournalResource; use App\Http\Resources\PopularViolationResource; use App\Http\Resources\RegulationResource; use App\Http\Resources\RepairStudentResource; +use App\Http\Resources\StudentPermissionResource; use App\Http\Resources\StudentPointResource; use App\Models\User; use App\Services\EmployeeJournalService; @@ -32,6 +35,7 @@ class StafApiController extends Controller private EmployeeJournalInterface $employeeJournal; private RegulationInterface $regulation; private AttendanceRuleInterface $attendanceRule; + private AttendanceInterface $attendance; public function __construct( AttendanceRuleInterface $attendanceRule, @@ -43,6 +47,7 @@ public function __construct( EmployeeJournalService $journalService, EmployeeJournalInterface $employeeJournal, RegulationInterface $regulation, + AttendanceInterface $attendance, ) { $this->attendanceRule = $attendanceRule; @@ -54,6 +59,7 @@ public function __construct( $this->journalService = $journalService; $this->employeeJournal = $employeeJournal; $this->regulation = $regulation; + $this->attendance = $attendance; } /** @@ -213,4 +219,14 @@ public function popular_violations() return response()->json(['status' => 'success', 'message' => "Data Kosong",'code' => 400], 400); } } + + public function student_permissions(Request $request) + { + try { + $attendances = $this->attendance->getSickAndPermit($request, [AttendanceEnum::SICK->value, AttendanceEnum::PERMIT->value]); + return response()->json(['status' => 'success', 'message' => "Berhasil mengambil data",'code' => 200, 'data' => StudentPermissionResource::collection($attendances)], 200); + } catch (\Throwable $th) { + return response()->json(['status' => 'success', 'message' => "Data Kosong".$th->getMessage(),'code' => 400], 400); + } + } } diff --git a/app/Http/Resources/StudentPermissionResource.php b/app/Http/Resources/StudentPermissionResource.php new file mode 100644 index 00000000..7ae203ff --- /dev/null +++ b/app/Http/Resources/StudentPermissionResource.php @@ -0,0 +1,27 @@ + + */ + public function toArray(Request $request): array + { + return [ + 'id' => $this->id, + 'name' => $this->model->student->user->name, + 'profile' => $this->model->student->image != null ? asset(request()->root(). '/storage/'.$this->model->student->image) : asset(request()->root(). '/public/admin_assets/dist/images/profile/user-1.jpg'), + 'class' => $this->model->classroom->name, + 'date' => $this->created_at, + 'status' => $this->status->label(), + 'proof' => $this->proof != null ? asset(request()->root(). '/storage/'.$this->proof) : asset(request()->root(). '/public/admin_assets/dist/images/profile/user-1.jpg'), + ]; + } +} diff --git a/routes/api.php b/routes/api.php index 94d270d3..17fa69c9 100644 --- a/routes/api.php +++ b/routes/api.php @@ -90,6 +90,7 @@ Route::get('staf/list-repair', [StafApiController::class, 'list_repair']); Route::get('staf/list-point-student', [StafApiController::class, 'list_point_student']); Route::get('staf/popular-violations', [StafApiController::class, 'popular_violations']); +Route::get('staf/student-permissions', [StafApiController::class, 'student_permissions']); Route::get('teacher/class/{user}', [TeacherApiController::class, 'class']); Route::get('teacher/attendance/{user}', [TeacherApiController::class, 'teacher_attendance']);