45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
"""
|
|
Food schemas for the application
|
|
"""
|
|
from typing import Optional
|
|
from pydantic import Field
|
|
|
|
from app.schemas.base import BaseSchema, TimestampSchema
|
|
|
|
|
|
# Shared properties
|
|
class FoodBase(BaseSchema):
|
|
"""Base food schema with shared properties"""
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
calories_per_100g: Optional[float] = None
|
|
protein_g: Optional[float] = None
|
|
carbs_g: Optional[float] = None
|
|
fat_g: Optional[float] = None
|
|
fiber_g: Optional[float] = None
|
|
is_verified: Optional[bool] = False
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class FoodCreate(FoodBase):
|
|
"""Schema for creating a new food item"""
|
|
name: str
|
|
calories_per_100g: float = Field(..., gt=0)
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class FoodUpdate(FoodBase):
|
|
"""Schema for updating a food item"""
|
|
pass
|
|
|
|
|
|
class FoodInDBBase(FoodBase, TimestampSchema):
|
|
"""Base schema for food in database"""
|
|
id: int
|
|
created_by_id: Optional[int] = None
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Food(FoodInDBBase):
|
|
"""Schema for returning a food item via API"""
|
|
pass |