refactor PersonController; replace caching logic with GetPersonDataAction for improved maintainability and clarity

This commit is contained in:
F4ilji
2025-07-18 17:10:49 +05:00
parent de7ef99b47
commit 1fc793089c
5 changed files with 73 additions and 72 deletions
@@ -2,38 +2,22 @@
namespace App\Containers\User\UI\WEB\Controllers;
use App\Containers\User\Actions\GetPersonDataAction;
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 __construct(private readonly GetPersonDataAction $getPersonDataAction){}
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)
->whereHas('userDetail')
->firstOrFail()
);
$seo = Cache::remember(
CacheKeys::USER_PREFIX->value . 'seo_' . $slug,
now()->addHours(24),
fn() => $this->seoPageProvider->getSeoForModel($personData)
);
$person = new FullInfoPersonResource($personData);
$data = $this->getPersonDataAction->run($slug);
$person = new FullInfoPersonResource($data['personData']);
$seo = $data['seo'];
return Inertia::render('Client/Persons/Show', compact('person', 'seo'));
}