ldc-ovoteam/app/Http/Controllers/Front/ProductController.php

53 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Front;
use App\Contracts\Executor;
use App\Cqs\Queries\Products\GetCategoriesProductsQuery;
use App\Cqs\Queries\Recipes\GetRelatedRecipesQuery;
use App\Cqs\Queries\Recipes\GetRelatedRecipesQueryInput;
use App\Http\Controllers\Controller;
use App\Http\Requests\Front\Products\IndexProductRequest;
use Domain\Models\Entities\Product;
use Inertia\Inertia;
use Inertia\Response;
class ProductController extends Controller
{
public function __construct(
private readonly Executor $executor,
) {
}
public function index(
IndexProductRequest $request,
GetCategoriesProductsQuery $getCategoriesProducts,
): Response {
$categoriesProducts = $this->executor->execute(
$getCategoriesProducts,
$request->toGetCategoriesProductsQueryInput()
);
return Inertia::render('front/Pages/Products/Index', [
'categoriesProducts' => $categoriesProducts,
]);
}
public function show(
Product $product,
GetRelatedRecipesQuery $getRelatedRecipes,
): Response {
$relatedRecipes = $this->executor->execute(
$getRelatedRecipes,
new GetRelatedRecipesQueryInput($product->id(), 10)
);
return Inertia::render('front/Pages/Products/Show', [
'product' => $product,
'relatedRecipes' => $relatedRecipes,
]);
}
}