Skip to content

Commit

Permalink
api untuk attendance teacher
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdianS18 committed Nov 20, 2024
1 parent cbd7135 commit 568c318
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Contracts/Repositories/AttendanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function userToday(mixed $model, mixed $id): mixed
return $this->model->query()
->where('model_type', $model)
->where('model_id', $id)
->whereDay('created_at', now()->day)
->whereDay('created_at', today()->day)
->first();
}

Expand Down
29 changes: 27 additions & 2 deletions app/Http/Controllers/Api/TeacherApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

namespace App\Http\Controllers\Api;

use App\Contracts\Interfaces\AttendanceInterface;
use App\Contracts\Interfaces\ClassroomInterface;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Http\Resources\HistoryAttendanceResource;
use Illuminate\Http\Request;
use App\Models\User;
use Carbon\Carbon;

class TeacherApiController extends Controller
{
private EmployeeInterface $employee;
private ClassroomInterface $classroom;
private AttendanceInterface $attendance;

public function __construct(EmployeeInterface $employee, ClassroomInterface $classroom)
public function __construct(EmployeeInterface $employee, ClassroomInterface $classroom, AttendanceInterface $attendance)
{
$this->employee = $employee;
$this->classroom = $classroom;
$this->attendance = $attendance;
}

public function class(User $user)
Expand All @@ -29,6 +34,26 @@ public function class(User $user)
]]);
}

public function teacher_attendance(User $user)
{
$employee = $this->employee->getByUser($user->id);
$todayAttendance = $this->attendance->userToday('App\Models\Employee', $employee->id);
$history_attendance = $this->attendance->whereUser($employee->id, 'App\Models\Employee');

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

/**
* Show the form for creating a new resource.
*/
Expand Down
8 changes: 5 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@
Route::post('login', [LoginApiController::class, 'login']);
Route::get('user-detail/{user}', [LoginApiController::class, 'user_detail']);

Route::get('feedback-active', [PermissionController::class, 'is_active']);

Route::get('student/dashboard/{user}', [StudentApiController::class, 'index']);
Route::get('student/history-attendance/{user}', [StudentApiController::class, 'history_attendance']);
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']);
Route::get('student/repair/{user}', [StudentApiController::class, 'repair']);

Route::post('staf/create-journal/{user}', [StafApiController::class, 'create_journal']);
Route::get('staf/dashboard/{user}', [StafApiController::class, 'index']);
Route::get('staf/history-journals/{user}', [StafApiController::class, 'history_journals']);
Route::post('staf/create-journal/{user}', [StafApiController::class, 'create_journal']);
Route::get('staf/overview-header', [StafApiController::class, 'overview_header']);
Route::get('staf/max-point', [StafApiController::class, 'max_point']);
Route::get('staf/list-violation', [StafApiController::class, 'list_violation']);
Expand All @@ -92,6 +92,8 @@
Route::get('staf/popular-violations', [StafApiController::class, 'popular_violations']);

Route::get('teacher/class/{user}', [TeacherApiController::class, 'class']);
Route::get('teacher/attendance/{user}', [TeacherApiController::class, 'teacher_attendance']);

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

0 comments on commit 568c318

Please sign in to comment.