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,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Loaders;
|
||||
|
||||
class AliasesLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $aliases = [];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Loaders;
|
||||
|
||||
class MiddlewareLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middleware = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middlewareGroups = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $routeMiddleware = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $middlewarePriority = [];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Loaders;
|
||||
|
||||
class ProvidersLoader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $providers = [];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Models;
|
||||
|
||||
use App\Containers\InstituteStructure\Models\Faculty;
|
||||
use App\Ship\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class EducationalGroup extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
public function faculty(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Faculty::class);
|
||||
}
|
||||
public function schedules(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Schedule::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Models;
|
||||
|
||||
|
||||
use App\Ship\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Schedule extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = false;
|
||||
|
||||
protected $casts = [
|
||||
'file' => 'array',
|
||||
];
|
||||
|
||||
public function educationalGroup(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EducationalGroup::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Schedule\Models\EducationalGroup;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class EducationalGroupPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('view_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('update_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('delete_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('force_delete_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('restore_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, EducationalGroup $educationalGroup): bool
|
||||
{
|
||||
return $user->can('replicate_educational::group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_educational::group');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Schedule\Policies;
|
||||
|
||||
use App\Containers\User\Models\User;
|
||||
use App\Containers\Schedule\Models\Schedule;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class SchedulePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view_any_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('view_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->can('create_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('update_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('delete_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk delete.
|
||||
*/
|
||||
public function deleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('delete_any_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete.
|
||||
*/
|
||||
public function forceDelete(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('force_delete_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently bulk delete.
|
||||
*/
|
||||
public function forceDeleteAny(User $user): bool
|
||||
{
|
||||
return $user->can('force_delete_any_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore.
|
||||
*/
|
||||
public function restore(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('restore_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can bulk restore.
|
||||
*/
|
||||
public function restoreAny(User $user): bool
|
||||
{
|
||||
return $user->can('restore_any_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can replicate.
|
||||
*/
|
||||
public function replicate(User $user, Schedule $schedule): bool
|
||||
{
|
||||
return $user->can('replicate_schedule');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can reorder.
|
||||
*/
|
||||
public function reorder(User $user): bool
|
||||
{
|
||||
return $user->can('reorder_schedule');
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user