feat: implement product and attachment management service with supporting migrations and API controllers

This commit is contained in:
2026-06-29 12:13:21 -03:00
parent cd420e02d8
commit 49771ebb13
8 changed files with 128 additions and 9 deletions

View File

@@ -23,6 +23,9 @@ class ProductResource extends JsonResource
'nombre' => $this->nombre,
'descripcion' => $this->descripcion,
'precio' => $this->precio,
'images' => $this->whenLoaded('attachments', fn () =>
$this->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values()
),
'variants' => ProductVariantResource::collection($this->whenLoaded('variants')),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,

View File

@@ -25,9 +25,21 @@ class ProductVariantResource extends JsonResource
'precio' => $this->precio,
'product' => ProductResource::make($this->whenLoaded('product')),
'definitions' => ProductVariantDefinitionResource::collection($this->whenLoaded('definitions')),
'images' => $this->whenLoaded('attachments', fn () =>
$this->attachments->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))->values()
),
'images' => $this->whenLoaded('attachments', function () {
if ($this->attachments->isNotEmpty()) {
return $this->attachments
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
->values();
}
// Fallback: use product-level attachments when the variant has none
$this->loadMissing('product.attachments');
return $this->product?->attachments
?->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
?->values()
?? collect();
}),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];