- 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.
52 lines
1.4 KiB
PHP
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\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,
|
|
]);
|
|
}
|
|
}
|