2026-07-08 18:16:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
|
|
2026-07-09 15:41:15 +02:00
|
|
|
use App\Contracts\Directories\ProductDirectory;
|
2026-07-08 18:16:46 +02:00
|
|
|
use App\Contracts\Directories\RecipeDirectory;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\Front\Recipes\IndexRecipeRequest;
|
|
|
|
|
use Domain\Models\Entities\Recipe;
|
|
|
|
|
use Domain\Models\ValueObjects\Pagination;
|
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Inertia\Response;
|
|
|
|
|
|
|
|
|
|
class RecipeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly RecipeDirectory $recipeDirectory,
|
2026-07-09 15:41:15 +02:00
|
|
|
private readonly ProductDirectory $productDirectory,
|
2026-07-08 18:16:46 +02:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index(IndexRecipeRequest $request): Response
|
|
|
|
|
{
|
|
|
|
|
$categories = $request->getCategories();
|
|
|
|
|
$consumptionTimes = $request->getConsumptionTimes();
|
|
|
|
|
$inspirations = $request->getInspirations();
|
|
|
|
|
$seasons = $request->getSeasons();
|
|
|
|
|
$search = $request->getSearchValue() ?? '';
|
|
|
|
|
|
|
|
|
|
// * Load all recipes for client-side display
|
|
|
|
|
$allRecipes = [];
|
|
|
|
|
$page = 1;
|
|
|
|
|
$perPage = 100;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
$pagination = Pagination::ofPage($page, $perPage);
|
|
|
|
|
|
|
|
|
|
$paginatedRecipes = $this->recipeDirectory->getPaginatedRecipes(
|
|
|
|
|
pagination: $pagination,
|
|
|
|
|
productRanges: $categories,
|
|
|
|
|
consumptionTimes: $consumptionTimes,
|
|
|
|
|
inspirations: $inspirations,
|
|
|
|
|
seasons: $seasons,
|
|
|
|
|
search: $search
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($paginatedRecipes->items() as $recipe) {
|
|
|
|
|
$allRecipes[] = $recipe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page++;
|
|
|
|
|
} while ($page <= $paginatedRecipes->lastPage());
|
|
|
|
|
|
|
|
|
|
$mockedPaginatedRecipes = new LengthAwarePaginator(
|
|
|
|
|
items: $allRecipes,
|
|
|
|
|
total: count($allRecipes),
|
2026-07-09 11:02:22 +02:00
|
|
|
perPage: max(1, count($allRecipes)),
|
2026-07-08 18:16:46 +02:00
|
|
|
currentPage: 1,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return Inertia::render('front/Pages/Recipes/Index', [
|
|
|
|
|
'paginatedRecipes' => $mockedPaginatedRecipes,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(Recipe $recipe): Response
|
|
|
|
|
{
|
2026-07-09 15:41:15 +02:00
|
|
|
$relatedProducts = $this->productDirectory
|
|
|
|
|
->getRelatedProducts($recipe->id(), 10);
|
|
|
|
|
|
2026-07-08 18:16:46 +02:00
|
|
|
return Inertia::render('front/Pages/Recipes/Show', [
|
2026-07-09 15:41:15 +02:00
|
|
|
'recipe' => $recipe,
|
|
|
|
|
'relatedProducts' => $relatedProducts,
|
2026-07-08 18:16:46 +02:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|