Skip to content

Commit

Permalink
feat(api)! : create api read student permission
Browse files Browse the repository at this point in the history
  • Loading branch information
farahamaliaa committed Dec 4, 2024
1 parent 08b2361 commit 1f7174a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Http/Controllers/Api/StafApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -43,6 +47,7 @@ public function __construct(
EmployeeJournalService $journalService,
EmployeeJournalInterface $employeeJournal,
RegulationInterface $regulation,
AttendanceInterface $attendance,
)
{
$this->attendanceRule = $attendanceRule;
Expand All @@ -54,6 +59,7 @@ public function __construct(
$this->journalService = $journalService;
$this->employeeJournal = $employeeJournal;
$this->regulation = $regulation;
$this->attendance = $attendance;
}

/**
Expand Down Expand Up @@ -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);
}
}
}
27 changes: 27 additions & 0 deletions app/Http/Resources/StudentPermissionResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class StudentPermissionResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
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'),
];
}
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 1f7174a

Please sign in to comment.