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:
F4ilji
2025-05-12 08:47:43 +05:00
parent 76deaf75f3
commit c01016a154
620 changed files with 16218 additions and 6073 deletions
@@ -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'));
// }
}
@@ -0,0 +1,15 @@
<?php
use App\Containers\Schedule\UI\WEB\Controllers\ClientScheduleController;
use Illuminate\Support\Facades\Route;
Route::middleware('access-check')->group(function () {
// Расписание занятий
Route::get('/schedule', [ClientScheduleController::class, 'index'])->name('client.schedule.index');
Route::get('/schedule/{id}', [ClientScheduleController::class, 'show'])->name('client.schedule.show');
});
@@ -0,0 +1,25 @@
<?php
namespace App\Containers\Schedule\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class EducationalGroupResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'schedules' => ScheduleGroupResource::collection($this->schedules),
'faculty' => $this->faculty->title,
];
}
}
@@ -0,0 +1,22 @@
<?php
namespace App\Containers\Schedule\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class ScheduleGroupResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'file' => $this->file,
];
}
}