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
+14
View File
@@ -0,0 +1,14 @@
<?php
use App\Services\VK\VkAuthService;
use Illuminate\Support\Facades\Route;
Route::middleware(['web', 'superadmin'])->group(function () {
Route::get('/login/vk', [VkAuthService::class, 'redirectToProvider'])->name('vk.login');
Route::get('/login/vk/callback', [VkAuthService::class, 'handleProviderCallback'])->name('vk.callback');
Route::get('/vk-get-token', [VkAuthService::class, 'getToken'])->name('vk.getToken');
Route::get('/vk-refresh-token', [VkAuthService::class, 'refresh'])->name('vk.refreshToken');
Route::get('/vk-logout', [VkAuthService::class, 'logout'])->name('vk.logout');
});
@@ -0,0 +1,40 @@
<?php
namespace App\Containers\User\UI\WEB\Controllers;
use App\Containers\User\Models\User;
use App\Containers\User\UI\WEB\Transformers\FullInfoPersonResource;
use App\Ship\Contracts\SeoServiceInterface;
use App\Ship\Controllers\Controller;
use App\Ship\Enums\CacheKeys;
use Illuminate\Support\Facades\Cache;
use Inertia\Inertia;
class PersonController extends Controller
{
public function __construct(readonly SeoServiceInterface $seoPageProvider){}
public function show(string $slug)
{
$personData = Cache::remember(
CacheKeys::USER_PREFIX->value . $slug,
now()->addHours(24),
fn() => User::with(['userDetail', 'departments_work.faculty', 'departments_teach.faculty', 'divisions', 'faculties'])
->where('slug', $slug)
->firstOrFail()
);
$seo = Cache::remember(
CacheKeys::USER_PREFIX->value . 'seo_' . $slug,
now()->addHours(24),
fn() => $this->seoPageProvider->getSeoForModel($personData)
);
$person = new FullInfoPersonResource($personData);
return Inertia::render('Client/Persons/Show', compact('person', 'seo'));
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
use App\Containers\User\UI\WEB\Controllers\PersonController;
use Illuminate\Support\Facades\Route;
Route::middleware('signed')->get('invitation/{invitation}/accept', \App\Livewire\AcceptInvitation::class)
->name('invitation.accept');
Route::middleware('access-check')->group(function () {
Route::get('/persons/{slug}', [PersonController::class, 'show'])->name('client.person.show');
});
@@ -0,0 +1,26 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class FullInfoPersonResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'details' => new PersonDetailResource($this->whenLoaded('userDetail')),
'departments_work' => PersonDepartmentsWorkResource::collection($this->whenLoaded('departments_work')),
'departments_teach' => PersonDepartmentsTeachResource::collection($this->whenLoaded('departments_teach')),
'divisions_works' => PersonDivisionsWorkResource::collection($this->whenLoaded('divisions')),
'faculties_works' => PersonFacultiesWorkResource::collection($this->whenLoaded('faculties'))
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDepartmentPreviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'academicTitle' => $this->userDetail->academicTitle ?? null,
'contactPhone' => $this->pivot->service_phone,
'contactEmail' => $this->pivot->service_email,
'cabinet' => $this->pivot->cabinet,
'photo' => $this->userDetail->photo ?? null,
'position' => $this->pivot->position,
];
}
}
@@ -0,0 +1,28 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDepartmentTeachPreviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'academicTitle' => $this->userDetail->academicTitle ?? null,
'contactPhone' => $this->pivot->service_phone,
'contactEmail' => $this->pivot->service_email,
'cabinet' => $this->pivot->cabinet,
'photo' => $this->userDetail->photo ?? null,
'position' => $this->pivot->teaching_position,
];
}
}
@@ -0,0 +1,26 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDepartmentsTeachResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id_department' => $this->id,
'title' => $this->title,
'faculty_title' => $this->faculty->title,
'slug' => $this->slug,
'faculty_slug' => $this->faculty->slug,
'position' => $this->pivot->teaching_position,
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDepartmentsWorkResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id_department' => $this->id,
'title' => $this->title,
'faculty_title' => $this->faculty->title,
'slug' => $this->slug,
'faculty_slug' => $this->faculty->slug,
'position' => $this->pivot->position,
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDetailResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return parent::toArray($request);
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDivisionPreviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'academicTitle' => $this->userDetail->academicTitle,
'contactPhone' => $this->pivot->service_phone,
'contactEmail' => $this->pivot->service_email,
'cabinet' => $this->pivot->cabinet,
'photo' => $this->userDetail->photo,
'administrativePosition' => $this->pivot->administrativePosition,
'sort' => $this->pivot->sort,
'details' => $this->userDetail,
];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonDivisionsWorkResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id_division' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'position' => $this->pivot->administrativePosition,
];
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonFacultiesWorkResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id_faculty' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'position' => $this->pivot->position,
];
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Containers\User\UI\WEB\Transformers;
use App\Ship\Resources\JsonResource;
class PersonFacultyPreviewResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'academicTitle' => $this->userDetail->academicTitle,
'contactPhone' => $this->pivot->service_phone,
'contactEmail' => $this->pivot->service_email,
'cabinet' => $this->pivot->cabinet,
'photo' => $this->userDetail->photo,
'position' => $this->pivot->position,
];
}
}