ldc-ovoteam/app/Http/Controllers/Front/ProductController.php
Jérémy Munsch 1a12569395
feat(directory): update ProductDirectory to use ProductId
- Changed the find method to accept ProductId instead of int.
- Added findBySlug method to retrieve products by slug.
- Updated getCategoryProducts method to return CategoryProducts type.

feat(eloquent): implement findBySlug in EloquentProductDirectory

- Implemented findBySlug method to retrieve products by slug.
- Updated find method to handle ProductId.

feat(dto): enhance CategoryProducts to serialize product IDs

- Updated CategoryProducts to serialize product IDs as strings.

feat(controller): modify ProductController to handle search limits

- Set limitPerCategory to -1 for search functionality.

refactor(model): change Product model ID to UUID

- Changed the id field in Product model to UUID.
- Updated related methods to handle UUIDs.

feat(migration): alter products and recipes tables for UUIDs

- Updated migrations to use UUIDs for primary keys in products and recipes tables.
- Adjusted foreign key constraints in product_recipe table.

feat(route): add route model binding for products

- Implemented route model binding for products using ProductId and slug.

chore(seed): remove CSV import calls from MandatorySeeder

- Removed calls to ImportProductsCsvSeeder and ImportRecipesCsvSeeder.

feat(entity): create ProductId and RecipeId value objects

- Added ProductId and RecipeId classes to encapsulate UUIDs.

feat(frontend): update TypeScript interfaces for products

- Updated TypeScript interfaces to reflect changes in product structure.
2026-09-21 11:43:39 +02:00

69 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Controllers\Front;
use App\Contracts\Directories\ProductDirectory;
use App\Http\Controllers\Controller;
use App\Http\Requests\Front\Products\IndexProductRequest;
use Domain\Models\Entities\Product;
use Domain\Models\ValueObjects\Products\ProductCategory;
use Inertia\Inertia;
use Inertia\Response;
class ProductController extends Controller
{
public function __construct(
private readonly ProductDirectory $productDirectory,
) {
}
public function index(IndexProductRequest $request): Response
{
$categories = $request->getCategories();
$breedingMethods = $request->getBreedingMethods();
$technologies = $request->getTechnologies();
$businesses = $request->getBusinesses();
$isEgalim = $request->getIsEgalim();
$search = $request->getSearchValue() ?? '';
$categoriesProducts = [];
if (count($categories) === 0) {
$categories = ! $request->hasFilter() ? [
ProductCategory::OMELETS_AND_DELI_AND_DESSERT_LINES,
ProductCategory::HARD_BOILED_EGGS,
] : ProductCategory::cases();
}
foreach ($categories as $category) {
$result = $this->productDirectory->getCategoryProducts(
category: $category,
breedingMethods: $breedingMethods,
technologies: $technologies,
businesses: $businesses,
isEgalim: $isEgalim,
search: $search,
// * No limit on search is volontary, limit is done in front, the creative team did not mind the pagination work.
limitPerCategory: -1
);
if ($result !== null) {
$categoriesProducts[] = $result;
}
}
return Inertia::render('front/Pages/Products/Index', [
'categoriesProducts' => $categoriesProducts,
]);
}
public function show(Product $product): Response
{
return Inertia::render('front/Pages/Products/Show', [
'product' => $product,
]);
}
}