Skip to content

Commit

Permalink
update response api untuk attendance guru
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdianS18 committed Nov 22, 2024
1 parent c8dff8b commit f3b92b7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/Contracts/Interfaces/ModelHasRfidInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ public function searchMaster(Request $request): mixed;
public function getStudentRfid(): mixed;
public function delete(string $model_type, mixed $model_id) : mixed;
public function count(): mixed;
public function first(string $model_type, mixed $model_id): mixed;
}
5 changes: 5 additions & 0 deletions app/Contracts/Repositories/ModelHasRfidRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function delete(string $model_type, mixed $model_id): mixed
return $this->model->query()->where('model_type', $model_type)->where('model_id', $model_id)->delete();
}

public function first(string $model_type, mixed $model_id): mixed
{
return $this->model->query()->where('model_type', $model_type)->where('model_id', $model_id)->first();
}

public function paginate(): mixed
{
return $this->model->query()->latest()->paginate(10);
Expand Down
55 changes: 39 additions & 16 deletions app/Http/Controllers/Api/TeacherApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace App\Http\Controllers\Api;

use App\Contracts\Interfaces\AttendanceInterface;
use App\Contracts\Interfaces\AttendanceRuleInterface;
use App\Contracts\Interfaces\ClassroomInterface;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\FeedbackInterface;
use App\Contracts\Interfaces\LessonScheduleInterface;
use App\Contracts\Interfaces\ModelHasRfidInterface;
use App\Contracts\Interfaces\Teachers\TeacherJournalInterface;
use App\Contracts\Interfaces\TeacherSubjectInterface;
use App\Http\Controllers\Controller;
Expand All @@ -30,6 +32,8 @@ class TeacherApiController extends Controller
private TeacherJournalInterface $teacherJournal;
private TeacherSubjectInterface $teacherSubject;
private FeedbackInterface $feedback;
private ModelHasRfidInterface $modelHasRfid;
private AttendanceRuleInterface $attendanceRule;

public function __construct(
EmployeeInterface $employee,
Expand All @@ -39,6 +43,8 @@ public function __construct(
TeacherJournalInterface $teacherJournal,
TeacherSubjectInterface $teacherSubject,
FeedbackInterface $feedback,
ModelHasRfidInterface $modelHasRfid,
AttendanceRuleInterface $attendanceRule,
)
{
$this->employee = $employee;
Expand All @@ -48,6 +54,8 @@ public function __construct(
$this->teacherJournal = $teacherJournal;
$this->teacherSubject = $teacherSubject;
$this->feedback = $feedback;
$this->modelHasRfid = $modelHasRfid;
$this->attendanceRule = $attendanceRule;
}

public function class(User $user)
Expand Down Expand Up @@ -78,24 +86,39 @@ public function teacher_attendance(User $user)
$employee = $this->employee->getByUser($user->id);
$history_attendance = $this->attendance->whereUser($employee->id, 'App\Models\Employee');
$single_attendance = $this->attendance->userToday('App\Models\Employee', $employee->id);
$rule_rfid = $this->modelHasRfid->first('App\Models\Employee', $employee->id);
$rule_day = $this->attendanceRule->whereDayRole(today()->format('l'),'teacher');

if ($rule_rfid) {
return response()->json(['status' => 'success', 'message' => "Berhasil mengambil data",'code' => 200,
'attendance_now' => [
'day' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('l') : now()->translatedFormat('l'),
'date' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('d') : now()->translatedFormat('d'),
'month' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('M') : now()->translatedFormat('M'),
'date_complate' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('l, j F Y') : now()->translatedFormat('l, j F Y'),
'check_in' => $single_attendance ? ($single_attendance->checkin == null ? '-' : \Carbon\Carbon::parse($single_attendance->checkin)->format('H:i')) : '-',
'check_out' => $single_attendance ? ($single_attendance->checkout == null ? '-' : \Carbon\Carbon::parse($single_attendance->checkout)->format('H:i')) : '-',
'status' => $single_attendance ? $single_attendance->status->label() : '',
],
'attendance_history' => $history_attendance->count() > 0 ? HistoryAttendanceResource::collection($history_attendance) : 'Data Kosong',
]);
} else if ($rule_day->is_holiday == true) {
return response()->json(['status' => 'success', 'message' => "Berhasil mengambil data",'code' => 200,
'attendance_now' => [
'day' => now()->translatedFormat('l'),
'date' => now()->translatedFormat('d'),
'month' => now()->translatedFormat('M'),
'date_complate' => now()->translatedFormat('l, j F Y'),
'check_in' => '-',
'check_out' => '-',
'status' => 'Libur',
],
'attendance_history' => $history_attendance->count() > 0 ? HistoryAttendanceResource::collection($history_attendance) : 'Data Kosong',
]);
} else {
return response()->json(['status' => 'success', 'message' => "Data Kosong", 'code' => 200, 'message_attendance' => "Anda Belum memiliki RFID"], 200);
}

// if () {

// }

return response()->json(['status' => 'success', 'message' => "Berhasil mengambil data",'code' => 200,
'attendance_now' => [
'day' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('l') : now()->translatedFormat('l'),
'date' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('d') : now()->translatedFormat('d'),
'month' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('M') : now()->translatedFormat('M'),
'date_complate' => $single_attendance ? Carbon::parse($single_attendance->created_at)->translatedFormat('l, j F Y') : now()->translatedFormat('l, j F Y'),
'check_in' => $single_attendance ? ($single_attendance->checkin == null ? '-' : \Carbon\Carbon::parse($single_attendance->checkin)->format('H:i')) : '-',
'check_out' => $single_attendance ? ($single_attendance->checkout == null ? '-' : \Carbon\Carbon::parse($single_attendance->checkout)->format('H:i')) : '-',
'status' => $single_attendance ? $single_attendance->status->label() : '',
],
'attendance_history' => $history_attendance->count() > 0 ? HistoryAttendanceResource::collection($history_attendance) : 'Data Kosong',
]);
}

public function today_lesson_schedule(User $user)
Expand Down

0 comments on commit f3b92b7

Please sign in to comment.