refactor ClientWidgetContactController and ClientWidgetPageReferenceListController; replace caching logic with action classes for widget data retrieval, enhancing code clarity and maintainability
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Widget\Actions;
|
||||
|
||||
use App\Containers\Widget\Tasks\FindPageReferenceListBySlugTask;
|
||||
use App\Containers\Widget\UI\API\Transformers\PageReferenceListResource;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class GetPageReferenceListPageAction
|
||||
{
|
||||
public function __construct(private FindPageReferenceListBySlugTask $findPageReferenceListBySlugTask)
|
||||
{
|
||||
}
|
||||
|
||||
public function run(string $slug): PageReferenceListResource
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::PAGE_REFERENCE_LIST_PREFIX->value . $slug,
|
||||
now()->addWeek(),
|
||||
function () use ($slug) {
|
||||
return new PageReferenceListResource(
|
||||
$this->findPageReferenceListBySlugTask->run($slug)
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user