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

This commit is contained in:
F4ilji
2025-07-22 18:22:04 +05:00
parent 7a8a6e023d
commit 528a4b24b0
19 changed files with 320 additions and 110 deletions
@@ -2,26 +2,17 @@
namespace App\Containers\Widget\UI\API\Controllers;
use App\Containers\Widget\Models\Slider;
use App\Containers\Widget\Actions\GetSliderBySlugAction;
use App\Ship\Controllers\Controller;
use Illuminate\Support\Facades\Cache;
class ClientWidgetSliderController extends Controller
{
public function __construct(
private readonly GetSliderBySlugAction $getSliderBySlugAction
) {}
public function show(string $slug): ?object
{
$cacheKey = 'slider_' . $slug;
return Cache::remember($cacheKey, now()->addHour(), function () use ($slug) {
$slider = Slider::query()
->where('slug', $slug)
->where('is_active', true)
->with(['slides' => function($query) {
$query->where('is_active', true);
}])
->firstOrFail();
return $slider ?: null;
});
return $this->getSliderBySlugAction->run($slug);
}
}