fix(phase1): add photo fields to schemas and set datetime default
This commit is contained in:
@@ -54,7 +54,7 @@ class Item(Base):
|
||||
# Photo fields for item onboarding
|
||||
photo_path = Column(String, nullable=True)
|
||||
photo_thumbnail_path = Column(String, nullable=True)
|
||||
photo_upload_date = Column(DateTime, nullable=True)
|
||||
photo_upload_date = Column(DateTime, default=datetime.datetime.now, nullable=True)
|
||||
|
||||
# Generic box/container association for multi-item OCR scanning
|
||||
box_label = Column(String, index=True, nullable=True)
|
||||
|
||||
@@ -107,7 +107,7 @@ def create_item(
|
||||
detail={
|
||||
"message": f"Item with Part Number '{item.barcode}' already exists in inventory.",
|
||||
"existing_id": existing.id,
|
||||
"existing_item": schemas.Item.model_validate(existing).model_dump()
|
||||
"existing_item": schemas.Item.model_validate(existing).model_dump(mode='json')
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, field_serializer
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# --- Categories ---
|
||||
@@ -54,6 +55,9 @@ class ItemBase(BaseModel):
|
||||
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):
|
||||
@@ -65,3 +69,8 @@ class Item(ItemBase):
|
||||
|
||||
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
|
||||
|
||||
@@ -34,7 +34,9 @@ class TestItemPhotoFields:
|
||||
retrieved = test_db.query(Item).filter_by(id=item.id).first()
|
||||
assert retrieved.photo_path is None
|
||||
assert retrieved.photo_thumbnail_path is None
|
||||
assert retrieved.photo_upload_date is None
|
||||
# photo_upload_date now has a default of datetime.now, so it should be populated
|
||||
assert retrieved.photo_upload_date is not None
|
||||
assert isinstance(retrieved.photo_upload_date, datetime)
|
||||
|
||||
def test_photo_fields_can_store_values(self, test_db):
|
||||
"""Test that photo fields can store string and datetime values."""
|
||||
@@ -78,4 +80,6 @@ class TestItemPhotoFields:
|
||||
retrieved = test_db.query(Item).filter_by(id=item.id).first()
|
||||
assert retrieved.photo_path == "/images/items/photo-003.jpg"
|
||||
assert retrieved.photo_thumbnail_path is None
|
||||
assert retrieved.photo_upload_date is None
|
||||
# photo_upload_date gets default timestamp even when explicitly set to None
|
||||
assert retrieved.photo_upload_date is not None
|
||||
assert isinstance(retrieved.photo_upload_date, datetime)
|
||||
|
||||
Reference in New Issue
Block a user