Skip to content

Commit

Permalink
list point siswa
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdianS18 committed Nov 8, 2024
1 parent 1d1323d commit dcd2c32
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/Contracts/Interfaces/StudentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public function getByPoint(Request $request) : mixed;
public function whereClassroomStudent(mixed $id) : mixed;
public function highestPoint(mixed $query): mixed;
public function orderByPoint(): mixed;
public function getByApi(Request $request): mixed;
}
11 changes: 11 additions & 0 deletions app/Contracts/Repositories/StudentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,15 @@ public function highestPoint(mixed $query): mixed
->where('point', '>', $query)
->count();
}

public function getByApi(Request $request): mixed
{
return $this->model->query()
->when($request->search, function($query) use ($request){
$query->when($request->search, function($q) use($request){
$q->whereRelation('user', 'name', 'LIKE', '%' . $request->search . '%');
});
})
->get();
}
}
7 changes: 7 additions & 0 deletions app/Http/Controllers/Api/StafApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Http\Resources\EmployeeJournalResource;
use App\Http\Resources\RegulationResource;
use App\Http\Resources\RepairStudentResource;
use App\Http\Resources\StudentPointResource;
use App\Models\User;
use App\Services\EmployeeJournalService;
use Carbon\Carbon;
Expand Down Expand Up @@ -138,4 +139,10 @@ public function list_repair()
}),
]);
}

public function list_point_student(Request $request)
{
$students = $this->student->getByApi($request);
return response()->json(['status' => 'success', 'message' => "Berhasil mengambil data",'code' => 200, 'data' => StudentPointResource::collection($students),]);
}
}
28 changes: 28 additions & 0 deletions app/Http/Resources/StudentPointResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Resources;

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

class StudentPointResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'image' => $this->image != null ? asset(request()->root(). '/storage/'.$this->image) : asset(request()->root(). '/public/admin_assets/dist/images/profile/user-1.jpg'),
'name' => $this->user->name,
'email' => $this->user->email,
'class' => $this->classroomStudents()->latest()->first()->classroom->name,
'nisn' => $this->nisn,
'gender' => $this->gender->label(),
'point' => $this->point
];
}
}
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
Route::get('staf/max-point', [StafApiController::class, 'max_point']);
Route::get('staf/list-violation', [StafApiController::class, 'list_violation']);
Route::get('staf/list-repair', [StafApiController::class, 'list_repair']);
Route::get('staf/list-point-student', [StafApiController::class, 'list_point_student']);

Route::get('lesson-schedule/{user}', [LessonScheduleApiController::class, 'index']);
Route::get('teacher-journal/{lessonSchedule}', [LessonScheduleApiController::class, 'create']);
Expand Down

0 comments on commit dcd2c32

Please sign in to comment.