Updated ProductPolicy and RecipePolicy to accept ProductDto in addition to Product. This change enhances the flexibility of the policies by allowing DTOs to be used for authorization checks. refactor(provider): simplify service provider bindings Refactored AppServiceProvider to simplify the binding of ProductDirectory and RecipeDirectory. Removed unnecessary dependencies and improved clarity. feat(route): update route bindings for front-end Changed route bindings for products and recipes to use frontProduct and frontRecipe. This improves clarity and consistency in route handling. fix(breadcrumbs): update breadcrumb checks for DTOs Updated breadcrumb generation to check for ProductDto and RecipeDto instead of their model counterparts. This ensures breadcrumbs function correctly with the new DTO structure. refactor(types): remove FilePath type and update schemas Removed the FilePath type definition and updated related schemas to use string directly. This simplifies type handling for file paths. style(entities): standardize naming conventions Updated naming conventions in Product and Recipe entities to use snake_case for consistency across the codebase. feat(frontend): update product and recipe pages for new DTO structure Modified front-end components to accommodate changes in the product and recipe data structures, ensuring compatibility with the new DTOs.
68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Contracts\Executor;
|
|
use App\Cqs\Queries\Products\FindProductByIdInput;
|
|
use App\Cqs\Queries\Products\FindProductBySlugInput;
|
|
use App\Cqs\Queries\Products\FindProductQuery;
|
|
use App\Cqs\Queries\Recipes\FindRecipeByIdInput;
|
|
use App\Cqs\Queries\Recipes\FindRecipeBySlugInput;
|
|
use App\Cqs\Queries\Recipes\FindRecipeQuery;
|
|
use App\Dto\ProductDto;
|
|
use App\Dto\RecipeDto;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Define your route model bindings, pattern filters, and other route configuration.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Route::bind('product', fn (string $value): ProductDto => $this->resolveProduct($value));
|
|
Route::bind('recipe', fn (string $value): RecipeDto => $this->resolveRecipe($value));
|
|
Route::bind('frontProduct', fn (string $value): ProductDto => $this->resolveProduct($value));
|
|
Route::bind('frontRecipe', fn (string $value): RecipeDto => $this->resolveRecipe($value));
|
|
}
|
|
|
|
private function resolveProduct(string $value): ProductDto
|
|
{
|
|
$executor = app()->make(Executor::class);
|
|
$findProductQuery = app()->make(FindProductQuery::class);
|
|
|
|
$input = Uuid::isValid($value)
|
|
? new FindProductByIdInput(Uuid::fromString($value), includeTrashed: $this->isBackRequest())
|
|
: new FindProductBySlugInput($value, includeTrashed: $this->isBackRequest());
|
|
|
|
return $executor->execute($findProductQuery, $input) ?? abort(404);
|
|
}
|
|
|
|
private function resolveRecipe(string $value): RecipeDto
|
|
{
|
|
$executor = app()->make(Executor::class);
|
|
$findRecipeQuery = app()->make(FindRecipeQuery::class);
|
|
|
|
$input = Uuid::isValid($value)
|
|
? new FindRecipeByIdInput(Uuid::fromString($value), includeTrashed: $this->isBackRequest())
|
|
: new FindRecipeBySlugInput($value, includeTrashed: $this->isBackRequest());
|
|
|
|
return $executor->execute($findRecipeQuery, $input) ?? abort(404);
|
|
}
|
|
|
|
private function isBackRequest(): bool
|
|
{
|
|
$prefix = config('uwil-backend.routes.prefix');
|
|
$adminPrefix = is_string($prefix) ? $prefix : 'admin';
|
|
|
|
return request()->is($adminPrefix . '/*')
|
|
|| request()->is($adminPrefix)
|
|
|| request()->is('back/*')
|
|
|| request()->is('back')
|
|
|| request()->routeIs('back.*');
|
|
}
|
|
}
|