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\ContactWidget;
use App\Containers\Widget\UI\API\Transformers\ContactWidgetResource;
use App\Containers\Widget\Actions\GetContactWidgetPageAction;
use App\Ship\Controllers\Controller;
use App\Ship\Enums\CacheKeys;
use Illuminate\Support\Facades\Cache;
class ClientWidgetContactController extends Controller
{
public function __construct(private GetContactWidgetPageAction $getContactWidgetPageAction)
{
}
public function show(string $slug)
{
return Cache::remember(
CacheKeys::CONTACT_WIDGET_PREFIX->value . $slug,
now()->addHours(12), // Кешируем на 12 часов
function () use ($slug) {
return new ContactWidgetResource(
ContactWidget::query()
->where('slug', $slug)
->firstOrFail()
);
}
);
return $this->getContactWidgetPageAction->run($slug);
}
}