siakad-itm/app/Services/Admin/Manage/Academic/ScheduleService.php
Yoga Pangestu 353829e053
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: Refactor Admin Manage structure into sub-namespaces for better organization
- Created sub-namespaces under Admin\Manage for Course, Academic, Announcement, Finance, and Service.
- Added new FormRequest classes for handling validation in each sub-namespace.
- Implemented Service classes for managing business logic related to each resource.
- Updated routes to reflect the new sub-namespace structure.
- Enhanced code organization and maintainability by grouping related functionalities.
2026-08-25 21:17:48 +07:00

49 lines
1.5 KiB
PHP

<?php
namespace App\Services\Admin\Manage\Academic;
use App\Models\Schedule;
use Illuminate\Database\Eloquent\Collection;
class ScheduleService
{
public function all(): Collection
{
return Schedule::query()
->select(['id', 'course_class_id', 'day_of_week', 'start_time', 'end_time', 'room', 'online_link'])
->with('courseClass.course:id,code,name')
->orderBy('start_time')
->get();
}
public function create(array $data): Schedule
{
return Schedule::create([
'course_class_id' => $data['course_class_id'],
'day_of_week' => $data['day_of_week'] ?? null,
'start_time' => $data['start_time'] ?? null,
'end_time' => $data['end_time'] ?? null,
'room' => $data['room'] ?? null,
'online_link' => $data['online_link'] ?? null,
]);
}
public function update(Schedule $schedule, array $data): Schedule
{
$schedule->course_class_id = $data['course_class_id'];
$schedule->day_of_week = $data['day_of_week'] ?? null;
$schedule->start_time = $data['start_time'] ?? null;
$schedule->end_time = $data['end_time'] ?? null;
$schedule->room = $data['room'] ?? null;
$schedule->online_link = $data['online_link'] ?? null;
$schedule->update();
return $schedule;
}
public function delete(Schedule $schedule): bool
{
return $schedule->delete();
}
}