2.2 KiB
2.2 KiB
Implementer — F-011 Product images
Summary
Implemented product image support inside the catalog module with a swappable storage boundary, PostgreSQL persistence, admin image endpoints, and product serialization that exposes ordered images with alt text.
Code changes
- Added image domain model and storage port:
project/src/modules/catalog/domain/image.ts. - Added product image repository port:
project/src/modules/catalog/domain/ports.ts. - Added use cases:
project/src/modules/catalog/application/image-use-cases.ts. - Added local-first URL storage adapter:
project/src/modules/catalog/infrastructure/local-product-image-storage.ts. - Added PostgreSQL image repository:
project/src/modules/catalog/infrastructure/pg-product-image-repository.ts. - Added migration:
project/migrations/009_catalog_product_images.js. - Extended catalog routes:
project/src/modules/catalog/api/catalog.routes.ts. - Added unit coverage:
project/src/modules/catalog/tests/image-use-cases.test.ts.
API behavior
GET /productos/:slugnow returns product-levelimages, ordered by repository ordering, withurl,altText,position, androle.GET /products/:id/imageslists product-level images.POST /products/:id/imagesattaches an image. Admin-only. Body:url,altText,role, optionalvariantId, optionalposition.DELETE /products/:id/images/:imageIddetaches an image. Admin-only.PATCH /products/:id/images/reorderreorders images. Admin-only.
Data rules
- Images can belong to a product or a product variant.
- Variant images must reference a variant that belongs to the same product.
- One
mainimage is allowed per product-level scope and per variant scope. - Images are ordered by
position, thencreated_at, thenid.
Evidence
cd project && npm run lint— PASS.cd project && npm run typecheck— PASS.cd project && npm test— PASS: 17 files passed, 7 skipped; 64 passed, 33 skipped../scripts/verify.sh— PASS.
Notes
- No new npm dependencies.
- No binary upload, CDN, resize/optimization pipeline, or external object-store SDK added.
- Integration tests remain skipped without
TEST_DATABASE_URL, consistent with prior features.