ldc-ovoteam/app/Providers/RouteServiceProvider.php

90 lines
2.7 KiB
PHP
Raw Permalink Normal View History

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-07-08 16:32:12 +02:00
<?php
declare(strict_types=1);
namespace App\Providers;
use App\Contracts\Directories\ProductDirectory;
use App\Contracts\Directories\RecipeDirectory;
use App\Models\Product;
use App\Models\Recipe;
use Domain\Models\Entities\Product as DomainProduct;
use Domain\Models\Entities\Recipe as DomainRecipe;
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-07-08 16:32:12 +02:00
use Domain\Models\ValueObjects\Entities\ProductId;
use Domain\Models\ValueObjects\Entities\RecipeId;
use Illuminate\Database\Eloquent\ModelNotFoundException;
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-07-08 16:32:12 +02:00
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
use Shared\Helpers\UuidHelper;
class RouteServiceProvider extends ServiceProvider
{
/**
* Define your route model bindings, pattern filters, and other route configuration.
*/
public function boot(): void
{
Route::bind('product', function (string $value) {
if (request()->is('back/*') || request()->is('back') || request()->routeIs('back.*')) {
return Product::withTrashed()
->where('id', $value)
->orWhere('slug', $value)
->firstOrFail();
}
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-07-08 16:32:12 +02:00
return $this->resolveProduct($value);
});
Route::bind('recipe', function (string $value) {
if (request()->is('back/*') || request()->is('back') || request()->routeIs('back.*')) {
return Recipe::withTrashed()
->where('id', $value)
->orWhere('slug', $value)
->firstOrFail();
}
return $this->resolveRecipe($value);
});
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-07-08 16:32:12 +02:00
}
private function resolveProduct(string $value): DomainProduct
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-07-08 16:32:12 +02:00
{
$productDirectory = app(ProductDirectory::class);
if (Str::isUuid($value) && UuidHelper::isV7(Uuid::fromString($value))) {
$product = $productDirectory->find(new ProductId(Uuid::fromString($value)));
}
if (! isset($product)) {
$product = $productDirectory->findBySlug($value);
}
if (! isset($product)) {
throw new ModelNotFoundException('Product not found');
}
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-07-08 16:32:12 +02:00
return $product;
}
private function resolveRecipe(string $value): DomainRecipe
{
$recipeDirectory = app(RecipeDirectory::class);
if (Str::isUuid($value) && UuidHelper::isV7(Uuid::fromString($value))) {
$recipe = $recipeDirectory->find(new RecipeId(Uuid::fromString($value)));
}
if (! isset($recipe)) {
$recipe = $recipeDirectory->findBySlug($value);
}
if (! isset($recipe)) {
throw new ModelNotFoundException('Recipe not found');
}
return $recipe;
}
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-07-08 16:32:12 +02:00
}