2026-07-08 14:55:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
|
|
2026-11-05 12:02:36 +01:00
|
|
|
use App\Contracts\Executor;
|
|
|
|
|
use App\Cqs\Queries\Products\GetCategoriesProductsQuery;
|
|
|
|
|
use App\Cqs\Queries\Recipes\GetRelatedRecipesQuery;
|
|
|
|
|
use App\Cqs\Queries\Recipes\GetRelatedRecipesQueryInput;
|
2026-11-05 16:49:42 +01:00
|
|
|
use App\Dto\ProductDto;
|
2026-07-08 14:55:18 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Front\Products\IndexProductRequest;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Inertia\Response;
|
|
|
|
|
|
|
|
|
|
class ProductController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-11-05 12:02:36 +01:00
|
|
|
private readonly Executor $executor,
|
2026-07-08 14:55:18 +02:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 12:02:36 +01:00
|
|
|
public function index(
|
|
|
|
|
IndexProductRequest $request,
|
|
|
|
|
GetCategoriesProductsQuery $getCategoriesProducts,
|
|
|
|
|
): Response {
|
|
|
|
|
$categoriesProducts = $this->executor->execute(
|
|
|
|
|
$getCategoriesProducts,
|
|
|
|
|
$request->toGetCategoriesProductsQueryInput()
|
|
|
|
|
);
|
2026-07-08 14:55:18 +02:00
|
|
|
|
|
|
|
|
return Inertia::render('front/Pages/Products/Index', [
|
|
|
|
|
'categoriesProducts' => $categoriesProducts,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 12:02:36 +01:00
|
|
|
public function show(
|
2026-11-05 16:49:42 +01:00
|
|
|
ProductDto $product,
|
2026-11-05 12:02:36 +01:00
|
|
|
GetRelatedRecipesQuery $getRelatedRecipes,
|
|
|
|
|
): Response {
|
|
|
|
|
$relatedRecipes = $this->executor->execute(
|
|
|
|
|
$getRelatedRecipes,
|
2026-11-05 16:49:42 +01:00
|
|
|
new GetRelatedRecipesQueryInput($product->getId(), 10)
|
2026-11-05 12:02:36 +01:00
|
|
|
);
|
2026-07-09 15:41:15 +02:00
|
|
|
|
2026-07-08 14:55:18 +02:00
|
|
|
return Inertia::render('front/Pages/Products/Show', [
|
2026-07-09 15:41:15 +02:00
|
|
|
'product' => $product,
|
|
|
|
|
'relatedRecipes' => $relatedRecipes,
|
2026-07-08 14:55:18 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|