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.
203 lines
6.8 KiB
PHP
203 lines
6.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Lib\PublicS3Disk;
|
|
use App\Models\Recipe;
|
|
use Carbon\CarbonInterface;
|
|
use Domain\Models\Entities\Recipe as DomainRecipe;
|
|
use Domain\Models\ValueObjects\Entities\RecipeId;
|
|
use Domain\Models\ValueObjects\Products\ProductCategory;
|
|
use Domain\Models\ValueObjects\Recipes\ConsumptionTime;
|
|
use Domain\Models\ValueObjects\Recipes\Inspiration;
|
|
use Domain\Models\ValueObjects\Recipes\Season;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use JsonSerializable;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class RecipeDto implements Arrayable, JsonSerializable, UrlRoutable
|
|
{
|
|
public function __construct(
|
|
public string $id,
|
|
public string $seoTitle,
|
|
public string $seoDescription,
|
|
public string $name,
|
|
public ?string $picture,
|
|
public ?string $pictureUrl,
|
|
public string $pictureAlt,
|
|
public string $pictureTitle,
|
|
public string $slug,
|
|
public ProductCategory $productCategory,
|
|
public ConsumptionTime $consomptionTime,
|
|
public Inspiration $inspiration,
|
|
public Season $season,
|
|
public ?string $description,
|
|
public ?string $details,
|
|
public string $ingredientsList,
|
|
public string $preparationSteps,
|
|
public ?string $tipsAndAdvices,
|
|
public ?CarbonInterface $createdAt,
|
|
public ?CarbonInterface $updatedAt,
|
|
public ?CarbonInterface $deletedAt,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(Recipe $recipe, PublicS3Disk $publicS3Disk): self
|
|
{
|
|
$picturePath = $recipe->picture?->value;
|
|
|
|
return new self(
|
|
id: (string) $recipe->id,
|
|
seoTitle: (string) $recipe->seo_title,
|
|
seoDescription: (string) $recipe->seo_description,
|
|
name: (string) $recipe->name,
|
|
picture: $picturePath,
|
|
pictureUrl: $picturePath !== null ? $publicS3Disk->publicUrlOf($picturePath) : null,
|
|
pictureAlt: (string) $recipe->picture_alt,
|
|
pictureTitle: (string) $recipe->picture_title,
|
|
slug: (string) $recipe->slug,
|
|
productCategory: $recipe->product_category,
|
|
consomptionTime: $recipe->consomption_time,
|
|
inspiration: $recipe->inspiration,
|
|
season: $recipe->season,
|
|
description: $recipe->description,
|
|
details: $recipe->details,
|
|
ingredientsList: (string) $recipe->ingredients_list,
|
|
preparationSteps: (string) $recipe->preparation_steps,
|
|
tipsAndAdvices: $recipe->tips_and_advices,
|
|
createdAt: $recipe->created_at,
|
|
updatedAt: $recipe->updated_at,
|
|
deletedAt: $recipe->deleted_at,
|
|
);
|
|
}
|
|
|
|
public static function fromEntity(
|
|
DomainRecipe $recipe,
|
|
PublicS3Disk $publicS3Disk
|
|
): self {
|
|
$picturePath = $recipe->picture;
|
|
|
|
return new self(
|
|
id: (string) $recipe->id->value,
|
|
seoTitle: (string) ($recipe->seoTitle ?? ''),
|
|
seoDescription: (string) ($recipe->seoDescription ?? ''),
|
|
name: $recipe->name,
|
|
picture: $picturePath,
|
|
pictureUrl: $picturePath !== null ? $publicS3Disk->publicUrlOf($picturePath) : null,
|
|
pictureAlt: '',
|
|
pictureTitle: '',
|
|
slug: $recipe->slug,
|
|
productCategory: $recipe->productRange,
|
|
consomptionTime: $recipe->consomptionTime,
|
|
inspiration: $recipe->inspiration,
|
|
season: $recipe->season,
|
|
description: $recipe->description,
|
|
details: $recipe->details,
|
|
ingredientsList: $recipe->ingredientsList,
|
|
preparationSteps: $recipe->preparationSteps,
|
|
tipsAndAdvices: $recipe->tipsAndAdvices,
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
deletedAt: null,
|
|
);
|
|
}
|
|
|
|
public static function dummyForZiggy(): self
|
|
{
|
|
return new self(
|
|
id: 'dummy-id',
|
|
seoTitle: 'dummy-seo-title',
|
|
seoDescription: 'dummy-seo-description',
|
|
name: 'dummy-name',
|
|
picture: null,
|
|
pictureUrl: null,
|
|
pictureAlt: 'dummy-picture-alt',
|
|
pictureTitle: 'dummy-picture-title',
|
|
slug: 'dummy-slug',
|
|
productCategory: ProductCategory::OMELETS_AND_DELI_AND_DESSERT_LINES,
|
|
consomptionTime: ConsumptionTime::LUNCH_DINNER,
|
|
inspiration: Inspiration::FRENCH_COOKING,
|
|
season: Season::ALL_YEAR,
|
|
description: 'dummy-description',
|
|
details: 'dummy-details',
|
|
ingredientsList: 'dummy-ingredients-list',
|
|
preparationSteps: 'dummy-preparation-steps',
|
|
tipsAndAdvices: 'dummy-tips-and-advices',
|
|
createdAt: null,
|
|
updatedAt: null,
|
|
deletedAt: null,
|
|
);
|
|
}
|
|
|
|
public function getId(): RecipeId
|
|
{
|
|
return new RecipeId(Uuid::fromString($this->id));
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'id';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'slug' => $this->slug,
|
|
'seo_title' => $this->seoTitle,
|
|
'seo_description' => $this->seoDescription,
|
|
'picture' => $this->pictureUrl,
|
|
'picture_alt' => $this->pictureAlt,
|
|
'picture_title' => $this->pictureTitle,
|
|
'product_category' => $this->productCategory->value,
|
|
'consomption_time' => $this->consomptionTime->value,
|
|
'inspiration' => $this->inspiration->value,
|
|
'season' => $this->season->value,
|
|
'description' => $this->description,
|
|
'details' => $this->details,
|
|
'ingredients_list' => $this->ingredientsList,
|
|
'preparation_steps' => $this->preparationSteps,
|
|
'tips_and_advices' => $this->tipsAndAdvices,
|
|
'created_at' => $this->createdAt?->toISOString(),
|
|
'updated_at' => $this->updatedAt?->toISOString(),
|
|
'deleted_at' => $this->deletedAt?->toISOString(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function jsonSerialize(): array
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|