ldc-ovoteam/app/Http/Controllers/Front/ProductController.php
Jérémy Munsch 6c691f77fc
feat(queries): add new product and recipe queries with inputs
- Implement GetCategoriesProductsQuery and GetCategoriesProductsQueryInput for product category retrieval.
- Implement GetRelatedProductsQuery and GetRelatedProductsQueryInput for related product fetching.
- Implement GetFrontRecipesQuery and GetFrontRecipesQueryInput for front-end recipe listing.
- Implement GetRelatedRecipesQuery and GetRelatedRecipesQueryInput for related recipe fetching.
- Update ProductController and RecipeController to utilize new query classes.
- Enhance IndexProductRequest and IndexRecipeRequest to convert requests to query inputs.
2026-11-05 12:02:36 +01:00

52 lines
1.4 KiB
PHP

<?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,
]);
}
}