feat(backend): products and categories point at the media library (platform-v2 step 5.2)

- products.media_id / categories.media_id (Alembic 0027): the old
  /static/product_images photos are processed into the library (named after
  their product; missing or unreadable files logged and skipped; the old
  folder is left on disk) and products.image_url goes. The static mount is gone.
- APIs give `image` {id, name, thumb, card, full}; a product's image_url is its
  card size. media_id on create/update (null clears); media.not_a_picture for
  a video. POST /api/products/{id}/image is gone: uploads go to /api/media.
- Products and categories register their media usage: a photo in use can't
  be deleted.
- Media: AVIF pictures (Pillow 12.3), GET /api/media/{id} gives each stored
  size's bytes and resolution and the uploader's name; upload processing moved
  into services/media.ingest (also used by the data move).
- QR menu photo push (contract C-3): the library's card size, WebP.
- tests: test_product_photos.py (7, incl. the 0027 data move); 497 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 15:57:50 +02:00
co-authored by Claude Opus 5.5
parent 238f8ec5a0
commit 5ad4c4ef55
15 changed files with 398 additions and 99 deletions
+11 -1
View File
@@ -14,6 +14,7 @@ class CategoryCreate(BaseModel):
parent_id: Optional[int] = None
general_sort_order: int = 0
auto_expanded: bool = False
media_id: Optional[int] = None # its picture in the media library (5.2)
class CategoryUpdate(BaseModel):
@@ -23,6 +24,7 @@ class CategoryUpdate(BaseModel):
parent_id: Optional[int] = None
general_sort_order: Optional[int] = None
auto_expanded: Optional[bool] = None
media_id: Optional[int] = None # null clears it (sent explicitly)
class CategoryOut(BaseModel):
@@ -33,6 +35,8 @@ class CategoryOut(BaseModel):
parent_id: Optional[int] = None
general_sort_order: int = 0
auto_expanded: bool = False
media_id: Optional[int] = None
image: Optional[dict] = None # {id, name, thumb, card, full} (services/media.image_of)
model_config = {"from_attributes": True}
@@ -347,6 +351,8 @@ class ProductBase(BaseModel):
# Fiscal printer (ΦΗΜ)
fiscal_name: Optional[str] = None
fiscal_vat_group_id: Optional[int] = None
# Its photo in the media library (plan step 5.2)
media_id: Optional[int] = None
class ProductCreate(ProductBase):
@@ -392,6 +398,7 @@ class ProductUpdate(BaseModel):
# Fiscal printer (ΦΗΜ)
fiscal_name: Optional[str] = None
fiscal_vat_group_id: Optional[int] = None
media_id: Optional[int] = None # null clears it (sent explicitly)
class ProductReorderItem(BaseModel):
@@ -413,7 +420,8 @@ class ProductOut(ProductBase):
ingredients: List[ProductIngredientOut] = []
preference_sets: List[PreferenceSetOut] = []
modifier_groups: List[ModifierGroupOut] = []
image_url: Optional[str] = None
image_url: Optional[str] = None # the card size of `image` (phones, counter)
image: Optional[dict] = None # {id, name, thumb, card, full} (services/media.image_of)
model_config = {"from_attributes": True}
@@ -444,6 +452,8 @@ class ProductOut(ProductBase):
'prep_zone_ids': [z.id for z in data.prep_zones] if hasattr(data, 'prep_zones') else [],
'sort_order': data.sort_order,
'image_url': data.image_url,
'image': data.image,
'media_id': data.media_id,
'sold_at': _sold_at(data),
'digital_available': bool(data.digital_available),
'digital_name': data.digital_name,