first commit

This commit is contained in:
Doar Mihai
2026-08-09 20:15:40 +03:00
commit 5301412a2a
165 changed files with 19789 additions and 0 deletions
+144
View File
@@ -0,0 +1,144 @@
<?php
namespace App\Dtos;
class RecipeDto
{
public ?int $id = null;
public ?string $title = null;
public ?string $slug = null;
public ?string $description = null;
public ?int $prepTime = null;
public ?int $cookTime = null;
public ?int $totalTime = null;
public ?int $servings = null;
public ?string $difficulty = null;
public ?string $cuisine = null;
public ?string $category = null;
public ?int $calories = null;
public ?string $featuredImage = null;
public ?string $videoUrl = null;
public ?int $status = null;
public ?int $viewsCount = null;
public ?float $ratingAvg = null;
public ?int $ratingCount = null;
public ?int $createdAt = null;
public ?int $updatedAt = null;
/** @var RecipeIngredientDto[] */
public array $ingredients = [];
/** @var RecipeStepDto[] */
public array $steps = [];
/** @var RecipeImageDto[] */
public array $images = [];
public ?RecipeNutritionDto $nutrition = null;
/** @var TagDto[] */
public array $tags = [];
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->title = $data['title'] ?? null;
$dto->slug = $data['slug'] ?? null;
$dto->description = $data['description'] ?? null;
$dto->prepTime = isset($data['prepTime']) ? (int)$data['prepTime'] : null;
$dto->cookTime = isset($data['cookTime']) ? (int)$data['cookTime'] : null;
$dto->totalTime = isset($data['totalTime']) ? (int)$data['totalTime'] : null;
$dto->servings = isset($data['servings']) ? (int)$data['servings'] : null;
$dto->difficulty = $data['difficulty'] ?? null;
$dto->cuisine = $data['cuisine'] ?? null;
$dto->category = $data['category'] ?? null;
$dto->calories = isset($data['calories']) ? (int)$data['calories'] : null;
$dto->featuredImage = $data['featuredImage'] ?? null;
$dto->videoUrl = $data['videoUrl'] ?? null;
$dto->status = isset($data['status']) ? (int)$data['status'] : null;
$dto->viewsCount = isset($data['viewsCount']) ? (int)$data['viewsCount'] : null;
$dto->ratingAvg = isset($data['ratingAvg']) ? (float)$data['ratingAvg'] : null;
$dto->ratingCount = isset($data['ratingCount']) ? (int)$data['ratingCount'] : null;
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
$dto->updatedAt = isset($data['updatedAt']) ? (int)$data['updatedAt'] : null;
// Parse nested DTOs
if (isset($data['ingredients']) && is_array($data['ingredients'])) {
$dto->ingredients = array_map(
fn($item) => RecipeIngredientDto::fromArray($item),
$data['ingredients']
);
}
if (isset($data['steps']) && is_array($data['steps'])) {
$dto->steps = array_map(
fn($item) => RecipeStepDto::fromArray($item),
$data['steps']
);
}
if (isset($data['images']) && is_array($data['images'])) {
$dto->images = array_map(
fn($item) => RecipeImageDto::fromArray($item),
$data['images']
);
}
if (isset($data['nutrition']) && is_array($data['nutrition'])) {
$dto->nutrition = RecipeNutritionDto::fromArray($data['nutrition']);
}
if (isset($data['tags']) && is_array($data['tags'])) {
$dto->tags = array_map(
fn($item) => TagDto::fromArray($item),
$data['tags']
);
}
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'description' => $this->description,
'prepTime' => $this->prepTime,
'cookTime' => $this->cookTime,
'totalTime' => $this->totalTime,
'servings' => $this->servings,
'difficulty' => $this->difficulty,
'cuisine' => $this->cuisine,
'category' => $this->category,
'calories' => $this->calories,
'featuredImage' => $this->featuredImage,
'videoUrl' => $this->videoUrl,
'status' => $this->status,
'viewsCount' => $this->viewsCount,
'ratingAvg' => $this->ratingAvg,
'ratingCount' => $this->ratingCount,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
'ingredients' => array_map(fn($item) => $item->toArray(), $this->ingredients),
'steps' => array_map(fn($item) => $item->toArray(), $this->steps),
'images' => array_map(fn($item) => $item->toArray(), $this->images),
'nutrition' => $this->nutrition?->toArray(),
'tags' => array_map(fn($item) => $item->toArray(), $this->tags),
];
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Dtos;
class RecipeImageDto
{
public ?int $id = null;
public ?string $imagePath = null;
public ?string $title = null;
public ?string $description = null;
public ?int $isFeatured = null;
public ?int $sortOrder = null;
public ?int $createdAt = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->imagePath = $data['imagePath'] ?? null;
$dto->title = $data['title'] ?? null;
$dto->description = $data['description'] ?? null;
$dto->isFeatured = isset($data['isFeatured']) ? (int)$data['isFeatured'] : null;
$dto->sortOrder = isset($data['sortOrder']) ? (int)$data['sortOrder'] : null;
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'imagePath' => $this->imagePath,
'title' => $this->title,
'description' => $this->description,
'isFeatured' => $this->isFeatured,
'sortOrder' => $this->sortOrder,
'createdAt' => $this->createdAt,
];
}
}
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace App\Dtos;
class RecipeIngredientDto
{
public ?int $id = null;
public ?int $ingredientId = null;
public ?string $ingredientName = null;
public ?string $ingredientSlug = null;
public ?string $ingredientCategory = null;
public ?string $quantity = null;
public ?string $unit = null;
public ?string $notes = null;
public ?int $sortOrder = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->ingredientId = isset($data['ingredientId']) ? (int)$data['ingredientId'] : null;
$dto->ingredientName = $data['ingredientName'] ?? null;
$dto->ingredientSlug = $data['ingredientSlug'] ?? null;
$dto->ingredientCategory = $data['ingredientCategory'] ?? null;
$dto->quantity = $data['quantity'] ?? null;
$dto->unit = $data['unit'] ?? null;
$dto->notes = $data['notes'] ?? null;
$dto->sortOrder = isset($data['sortOrder']) ? (int)$data['sortOrder'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'ingredientId' => $this->ingredientId,
'ingredientName' => $this->ingredientName,
'ingredientSlug' => $this->ingredientSlug,
'ingredientCategory' => $this->ingredientCategory,
'quantity' => $this->quantity,
'unit' => $this->unit,
'notes' => $this->notes,
'sortOrder' => $this->sortOrder,
];
}
}
+68
View File
@@ -0,0 +1,68 @@
<?php
namespace App\Dtos;
class RecipeNutritionDto
{
public ?int $id = null;
public ?int $calories = null;
public ?float $protein = null;
public ?float $carbohydrates = null;
public ?float $fat = null;
public ?float $saturatedFat = null;
public ?float $fiber = null;
public ?float $sugar = null;
public ?float $sodium = null;
public ?float $cholesterol = null;
public ?int $createdAt = null;
public ?int $updatedAt = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->calories = isset($data['calories']) ? (int)$data['calories'] : null;
$dto->protein = isset($data['protein']) ? (float)$data['protein'] : null;
$dto->carbohydrates = isset($data['carbohydrates']) ? (float)$data['carbohydrates'] : null;
$dto->fat = isset($data['fat']) ? (float)$data['fat'] : null;
$dto->saturatedFat = isset($data['saturatedFat']) ? (float)$data['saturatedFat'] : null;
$dto->fiber = isset($data['fiber']) ? (float)$data['fiber'] : null;
$dto->sugar = isset($data['sugar']) ? (float)$data['sugar'] : null;
$dto->sodium = isset($data['sodium']) ? (float)$data['sodium'] : null;
$dto->cholesterol = isset($data['cholesterol']) ? (float)$data['cholesterol'] : null;
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
$dto->updatedAt = isset($data['updatedAt']) ? (int)$data['updatedAt'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'calories' => $this->calories,
'protein' => $this->protein,
'carbohydrates' => $this->carbohydrates,
'fat' => $this->fat,
'saturatedFat' => $this->saturatedFat,
'fiber' => $this->fiber,
'sugar' => $this->sugar,
'sodium' => $this->sodium,
'cholesterol' => $this->cholesterol,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}
}
+53
View File
@@ -0,0 +1,53 @@
<?php
namespace App\Dtos;
class RecipeStepDto
{
public ?int $id = null;
public ?int $stepNumber = null;
public ?string $title = null;
public ?string $instruction = null;
public ?string $image = null;
public ?int $timeEstimate = null;
public ?int $sortOrder = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->stepNumber = isset($data['stepNumber']) ? (int)$data['stepNumber'] : null;
$dto->title = $data['title'] ?? null;
$dto->instruction = $data['instruction'] ?? null;
$dto->image = $data['image'] ?? null;
$dto->timeEstimate = isset($data['timeEstimate']) ? (int)$data['timeEstimate'] : null;
$dto->sortOrder = isset($data['sortOrder']) ? (int)$data['sortOrder'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'stepNumber' => $this->stepNumber,
'title' => $this->title,
'instruction' => $this->instruction,
'image' => $this->image,
'timeEstimate' => $this->timeEstimate,
'sortOrder' => $this->sortOrder,
];
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Dtos;
class TagDto
{
public ?int $id = null;
public ?string $name = null;
public ?string $slug = null;
public ?int $createdAt = null;
/**
* Create DTO from array
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): static
{
$dto = new static();
$dto->id = $data['id'] ?? null;
$dto->name = $data['name'] ?? null;
$dto->slug = $data['slug'] ?? null;
$dto->createdAt = isset($data['createdAt']) ? (int)$data['createdAt'] : null;
return $dto;
}
/**
* Convert DTO to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'createdAt' => $this->createdAt,
];
}
}