- 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.
35 lines
852 B
PHP
35 lines
852 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cqs\Queries\Recipes;
|
|
|
|
use App\Contracts\Directories\RecipeDirectory;
|
|
use App\Contracts\Query;
|
|
use App\Contracts\QueryInput;
|
|
use Domain\Models\Entities\Recipe;
|
|
use Webmozart\Assert\Assert;
|
|
|
|
/**
|
|
* @implements \App\Contracts\Query<\App\Cqs\Queries\Recipes\GetRelatedRecipesQueryInput, array<int, \Domain\Models\Entities\Recipe>>
|
|
*/
|
|
final readonly class GetRelatedRecipesQuery implements Query
|
|
{
|
|
public function __construct(
|
|
private RecipeDirectory $recipeDirectory,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return array<int, Recipe>
|
|
*/
|
|
public function __invoke(QueryInput $input): array
|
|
{
|
|
Assert::isAOf($input, GetRelatedRecipesQueryInput::class);
|
|
|
|
return $this->recipeDirectory->getRelatedRecipes(
|
|
$input->productId,
|
|
$input->limit
|
|
);
|
|
}
|
|
}
|