refactor ClientWidgetContactController and ClientWidgetPageReferenceListController; replace caching logic with action classes for widget data retrieval, enhancing code clarity and maintainability

This commit is contained in:
F4ilji
2025-07-21 22:45:55 +05:00
parent 3cac482409
commit eac29d8d1c
6 changed files with 104 additions and 30 deletions
@@ -2,26 +2,17 @@
namespace App\Containers\Widget\UI\API\Controllers;
use App\Containers\Widget\Models\PageReferenceList;
use App\Containers\Widget\UI\API\Transformers\PageReferenceListResource;
use App\Containers\Widget\Actions\GetPageReferenceListPageAction;
use App\Ship\Controllers\Controller;
use App\Ship\Enums\CacheKeys;
use Illuminate\Support\Facades\Cache;
class ClientWidgetPageReferenceListController extends Controller
{
public function __construct(private GetPageReferenceListPageAction $getPageReferenceListPageAction)
{
}
public function show(string $slug)
{
return Cache::remember(
CacheKeys::PAGE_REFERENCE_LIST_PREFIX->value . $slug,
now()->addWeek(), // Кешируем на неделю, так как справочники меняются редко
function () use ($slug) {
return new PageReferenceListResource(
PageReferenceList::query()
->where('slug', $slug)
->firstOrFail()
);
}
);
return $this->getPageReferenceListPageAction->run($slug);
}
}