- Database: Added photo_path, photo_thumbnail_path, photo_upload_date fields
- Services: ImageStorage (file ops) + ImageProcessor (image processing pipeline)
- API: POST/PUT /api/items/{id}/photo upload endpoints with validation
- API: GET /api/items/{id} returns photo URLs
- Static: FastAPI StaticFiles mount for /images/ directory
- Tests: 127+ comprehensive tests across all components
- Security: Fixed race conditions, path traversal, crop validation
- Ready for Phase 2 (frontend UI)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
89 lines
1.9 KiB
Python
89 lines
1.9 KiB
Python
from pydantic import BaseModel, field_serializer
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
|
|
|
|
# --- Photo Response ---
|
|
class PhotoResponse(BaseModel):
|
|
"""Photo metadata for item responses."""
|
|
thumbnail_url: str
|
|
full_url: str
|
|
uploaded_at: datetime
|
|
|
|
|
|
# --- Categories ---
|
|
class CategoryBase(BaseModel):
|
|
name: str
|
|
description: Optional[str] = None
|
|
|
|
|
|
class CategoryCreate(CategoryBase):
|
|
pass
|
|
|
|
|
|
class Category(CategoryBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# --- Colors ---
|
|
class ColorBase(BaseModel):
|
|
name: str
|
|
|
|
|
|
class ColorCreate(ColorBase):
|
|
pass
|
|
|
|
|
|
class Color(ColorBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# --- Items ---
|
|
class ItemBase(BaseModel):
|
|
name: str
|
|
category: str
|
|
category_id: Optional[int] = None
|
|
type: Optional[str] = None
|
|
barcode: str
|
|
part_number: Optional[str] = None
|
|
color: Optional[str] = None
|
|
description: Optional[str] = None
|
|
connector: Optional[str] = None
|
|
size: Optional[str] = None
|
|
ocr_text: Optional[str] = None
|
|
specs: Optional[str] = None
|
|
quantity: float = 0.0
|
|
min_quantity: float = 1.0
|
|
image_url: Optional[str] = None
|
|
box_label: Optional[str] = None
|
|
labels_data: Optional[str] = None
|
|
photo_path: Optional[str] = None
|
|
photo_thumbnail_path: Optional[str] = None
|
|
photo_upload_date: Optional[datetime] = None
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
pass
|
|
|
|
|
|
class Item(ItemBase):
|
|
id: int
|
|
photo_path: Optional[str] = None
|
|
photo_thumbnail_path: Optional[str] = None
|
|
photo_upload_date: Optional[datetime] = None
|
|
photo: Optional[PhotoResponse] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
@field_serializer('photo_upload_date', when_used='json')
|
|
def serialize_photo_upload_date(self, value: Optional[datetime]) -> Optional[str]:
|
|
"""Serialize datetime to ISO format string for JSON."""
|
|
return value.isoformat() if value else None
|