ldc-ovoteam/app/Http/Controllers/Front/RecipeController.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\GetRelatedProductsQuery;
use App\Cqs\Queries\Products\GetRelatedProductsQueryInput;
use App\Cqs\Queries\Recipes\GetFrontRecipesQuery;
use App\Http\Controllers\Controller;
use App\Http\Requests\Front\Recipes\IndexRecipeRequest;
use Domain\Models\Entities\Recipe;
use Inertia\Inertia;
use Inertia\Response;
class RecipeController extends Controller
{
public function __construct(
private readonly Executor $executor,
) {
}
public function index(
IndexRecipeRequest $request,
GetFrontRecipesQuery $getFrontRecipes,
): Response {
$paginatedRecipes = $this->executor->execute(
$getFrontRecipes,
$request->toGetFrontRecipesQueryInput()
);
return Inertia::render('front/Pages/Recipes/Index', [
'paginatedRecipes' => $paginatedRecipes,
]);
}
public function show(
Recipe $recipe,
GetRelatedProductsQuery $getRelatedProducts,
): Response {
$relatedProducts = $this->executor->execute(
$getRelatedProducts,
new GetRelatedProductsQueryInput($recipe->id(), 10)
);
return Inertia::render('front/Pages/Recipes/Show', [
'recipe' => $recipe,
'relatedProducts' => $relatedProducts,
]);
}
}