Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern - Improved code organization and maintainability - Fixed minor bugs and inconsistencies
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\UI\WEB\Controllers;
|
||||
|
||||
use App\Containers\Schedule\Models\EducationalGroup;
|
||||
use App\Containers\Schedule\UI\WEB\Transformers\EducationalGroupResource;
|
||||
use App\Ship\Contracts\SeoServiceInterface;
|
||||
use App\Ship\Controllers\Controller;
|
||||
use App\Ship\Enums\Education\FormEducation;
|
||||
use App\Ship\Requests\Request;
|
||||
|
||||
class ClientScheduleController extends Controller
|
||||
{
|
||||
public function __construct(readonly SeoServiceInterface $seoPageProvider){}
|
||||
|
||||
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->whereHas('schedules', function ($query) use ($favorite) {
|
||||
$query->whereIn('id', $favorite);
|
||||
});
|
||||
})
|
||||
->when(request()->input('form'), function ($query, $form) {
|
||||
$query->where('education_form_id', FormEducation::fromName($form)->value);
|
||||
|
||||
})
|
||||
->with('schedules')
|
||||
->with('faculty')
|
||||
->orderBy('faculty_id')
|
||||
->orderBy('title')
|
||||
->paginate(10);
|
||||
|
||||
$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 = [];
|
||||
foreach (FormEducation::cases() as $case) {
|
||||
$forms_education[$case->name] = $case->getLabel();
|
||||
}
|
||||
|
||||
$filters = [
|
||||
'form_education_filter' => [
|
||||
'type' => 'form',
|
||||
'value' => request()->input('form'),
|
||||
'param' => 'form'
|
||||
],
|
||||
'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,
|
||||
]
|
||||
);
|
||||
|
||||
// Возвращаем данные в представление
|
||||
}
|
||||
|
||||
// public function show($id)
|
||||
// {
|
||||
// $schedule = Schedule::find($id);
|
||||
// return Inertia::render('Client/Schedules/Show', compact('schedule'));
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user