refactor multiple widget controllers; replace caching logic with action classes for data retrieval, enhancing code clarity and maintainability
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user