refactor: split table models into Base/Table/Public for proper FastAPI serialization

Add ProductBase, ProductPublic, ProductWithInventory and
SkinConditionSnapshotBase, SkinConditionSnapshotPublic. Table models now inherit
from their Base counterpart and override JSON fields with sa_column. All
field_serializer hacks removed; FastAPI response models use the non-table Public
classes so Pydantic coerces raw DB dicts → typed models cleanly. ProductCreate
and SnapshotCreate now simply inherit their respective Base classes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Piotr Oleszczyk 2026-02-27 15:37:46 +01:00
parent 479be25112
commit c09acc7c81
15 changed files with 225 additions and 198 deletions

View file

@ -55,7 +55,9 @@ def test_list_filter_category(client, client_and_data=None):
"recommended_time": "both",
"leave_on": True,
}
r1 = client.post("/products", json={**base, "name": "Moist", "category": "moisturizer"})
r1 = client.post(
"/products", json={**base, "name": "Moist", "category": "moisturizer"}
)
r2 = client.post("/products", json={**base, "name": "Ser", "category": "serum"})
assert r1.status_code == 201
assert r2.status_code == 201
@ -96,7 +98,12 @@ def test_list_filter_is_medication(client):
# is_medication=True requires usage_notes (model validator)
client.post(
"/products",
json={**base, "name": "Med", "is_medication": True, "usage_notes": "Apply pea-sized amount"},
json={
**base,
"name": "Med",
"is_medication": True,
"usage_notes": "Apply pea-sized amount",
},
)
r = client.get("/products?is_medication=true")