diff --git a/app/Containers/Schedule/Actions/ListSchedulesAction.php b/app/Containers/Schedule/Actions/ListSchedulesAction.php new file mode 100644 index 0000000..4240432 --- /dev/null +++ b/app/Containers/Schedule/Actions/ListSchedulesAction.php @@ -0,0 +1,53 @@ +getFilteredEducationalGroupsTask->run($filters); + + $schedulesPaginate = $educationalGroups->toArray(); + unset($schedulesPaginate['data']); + $educationalGroups = EducationalGroupResource::collection($educationalGroups->items()); + + $schedulesByFaculty = $educationalGroups->groupBy(function ($group) { + return $group->faculty->title; + }); + + $schedulesByFaculty = $schedulesByFaculty->toArray(); + + $forms_education = $this->getAllFormsEducationTask->run(); + + $faculties = $this->getAllActiveFacultiesTask->run(); + + $filtersData = $this->buildScheduleFiltersTask->run($filters); + + $seo = $this->seoPageProvider->getSeoForCurrentPage(); + + return [ + 'filters' => $filtersData, + 'forms_education' => $forms_education, + 'schedulesByFaculty' => inertia()->deepMerge(fn() => $schedulesByFaculty), + 'schedules_paginator' => $schedulesPaginate, + 'seo' => $seo, + 'faculties' => $faculties, + ]; + } +} diff --git a/app/Containers/Schedule/Tasks/BuildScheduleFiltersTask.php b/app/Containers/Schedule/Tasks/BuildScheduleFiltersTask.php new file mode 100644 index 0000000..75b5157 --- /dev/null +++ b/app/Containers/Schedule/Tasks/BuildScheduleFiltersTask.php @@ -0,0 +1,52 @@ +filterBuilder->reset(); + + // 1. Поисковый фильтр + $this->filterBuilder->add( + key: 'search_filter', + type: 'search', + value: $requestFilters['search'] ?? null, + param: 'search' + ); + + // 2. Фильтр по форме образования + $this->filterBuilder->add( + key: 'form_education_filter', + type: 'form', + value: $requestFilters['form'] ?? null, + param: 'form' + ); + + // 3. Фильтр по факультету + $this->filterBuilder->add( + key: 'faculty_filter', + type: 'faculty', + value: $requestFilters['faculty'] ?? null, + param: 'faculty' + ); + + // 4. Фильтр избранного + $this->filterBuilder->add( + key: 'favorite_filter', + type: 'favorite', + value: $requestFilters['favorite'] ?? null, + param: 'favorite' + ); + + return $this->filterBuilder->get(); + } +} diff --git a/app/Containers/Schedule/Tasks/GetAllActiveFacultiesTask.php b/app/Containers/Schedule/Tasks/GetAllActiveFacultiesTask.php new file mode 100644 index 0000000..982e827 --- /dev/null +++ b/app/Containers/Schedule/Tasks/GetAllActiveFacultiesTask.php @@ -0,0 +1,13 @@ +where('is_active', true)->get(); + } +} diff --git a/app/Containers/Schedule/Tasks/GetAllFormsEducationTask.php b/app/Containers/Schedule/Tasks/GetAllFormsEducationTask.php new file mode 100644 index 0000000..6d9fecd --- /dev/null +++ b/app/Containers/Schedule/Tasks/GetAllFormsEducationTask.php @@ -0,0 +1,18 @@ +name] = $case->getLabel(); + } + + return $forms_education; + } +} diff --git a/app/Containers/Schedule/Tasks/GetFilteredEducationalGroupsTask.php b/app/Containers/Schedule/Tasks/GetFilteredEducationalGroupsTask.php new file mode 100644 index 0000000..9a51549 --- /dev/null +++ b/app/Containers/Schedule/Tasks/GetFilteredEducationalGroupsTask.php @@ -0,0 +1,37 @@ +has('schedules') + ->when(isset($filters['search']), function ($query) use ($filters) { + $query->whereRaw('LOWER(title) like ?', ["%".strtolower($filters['search'])."%"]); + }) + ->when(isset($filters['favorite']), function ($query) use ($filters) { + $query->whereIn('id', $filters['favorite']); + }) + ->when(isset($filters['form']), function ($query) use ($filters) { + $query->where('education_form_id', FormEducation::fromName($filters['form'])->value); + }) + ->when(isset($filters['faculty']), function ($query) use ($filters) { + $query->whereHas('faculty', function ($q) use ($filters) { + $q->where('slug', $filters['faculty']); + }); + }) + ->with('schedules') + ->with('faculty') + ->orderBy('faculty_id') + ->orderBy('title'); + + return $educationalGroups->paginate(10); + } +} diff --git a/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php b/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php index f4baaa1..8185a8d 100644 --- a/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php +++ b/app/Containers/Schedule/UI/WEB/Controllers/ClientScheduleController.php @@ -2,103 +2,22 @@ namespace App\Containers\Schedule\UI\WEB\Controllers; -use App\Containers\InstituteStructure\Models\Faculty; -use App\Containers\Schedule\Models\EducationalGroup; -use App\Containers\Schedule\UI\WEB\Transformers\EducationalGroupResource; -use App\Ship\Contracts\SeoServiceInterface; +use App\Containers\Schedule\Actions\ListSchedulesAction; use App\Ship\Controllers\Controller; -use App\Ship\Enums\Education\FormEducation; use Illuminate\Http\Request; class ClientScheduleController extends Controller { - public function __construct(readonly SeoServiceInterface $seoPageProvider){} + public function __construct( + private readonly ListSchedulesAction $listSchedulesAction, + ) {} public function index(Request $request) { - $educationalGroups = EducationalGroup::query() - ->has('schedules') - ->when(request()->input('search'), function ($query, $search) { - $query->whereRaw('LOWER(title) like ?', ["%".strtolower($search)."%"]); - }) - ->when(request()->input('favorite'), function ($query, $favorite) { - $query->whereIn('id', $favorite); - }) - ->when(request()->input('form'), function ($query, $form) { - $query->where('education_form_id', FormEducation::fromName($form)->value); - }) - ->when(request()->input('faculty'), function ($query, $facultySlug) { - $query->whereHas('faculty', function ($q) use ($facultySlug) { - $q->where('slug', $facultySlug); - }); - }) - ->with('schedules') - ->with('faculty') - ->orderBy('faculty_id') - ->orderBy('title') - ->paginate(10); + $filters = $request->only(['search', 'form', 'faculty', 'favorite']); - $schedulesPaginate = $educationalGroups->toArray(); - unset($schedulesPaginate['data']); - $educationalGroups = EducationalGroupResource::collection($educationalGroups->items()); + $data = $this->listSchedulesAction->run($filters); - - $schedulesByFaculty = $educationalGroups->groupBy(function ($group) { - return $group->faculty->title; - }); - - $schedulesByFaculty = $schedulesByFaculty->toArray(); - - $forms_education = []; - foreach (FormEducation::cases() as $case) { - $forms_education[$case->name] = $case->getLabel(); - } - - $faculties = Faculty::query()->where('is_active', true)->get(); - - $filters = [ - 'form_education_filter' => [ - 'type' => 'form', - 'value' => request()->input('form'), - 'param' => 'form' - ], - 'faculty_filter' => [ - 'type' => 'faculty', - 'value' => request()->input('faculty'), - 'param' => 'faculty' - ], - 'search_filter' => [ - 'type' => 'search', - 'value' => $request->input('search'), - 'param' => 'search' - ], - 'favorite_filter' => [ - 'type' => 'favorite', - 'value' => $request->input('favorite'), - 'param' => 'favorite' - ] - ]; - - $seo = $this->seoPageProvider->getSeoForCurrentPage(); - - return inertia()->render( - 'Client/Schedules/Index', - [ - 'filters' => $filters, - 'forms_education' => $forms_education, - 'schedulesByFaculty' => inertia()->deepMerge(fn() => $schedulesByFaculty), - 'schedules_paginator' => $schedulesPaginate, - 'seo' => $seo, - 'faculties' => $faculties, - ] - ); - - // Возвращаем данные в представление + return inertia()->render('Client/Schedules/Index', $data); } - -// public function show($id) -// { -// $schedule = Schedule::find($id); -// return Inertia::render('Client/Schedules/Show', compact('schedule')); -// } }