Add Food schema

This commit is contained in:
Backend IM Bot 2025-03-28 15:56:53 +00:00
parent 8a2c0c84f9
commit ce5cbbc805

View File

@ -1,34 +1,28 @@
from pydantic import BaseModel, Field, constr from pydantic import BaseModel, Field
from typing import Optional from typing import Optional, Union
from enum import Enum
class FoodCategory(str, Enum):
APPETIZER = "appetizer"
MAIN_COURSE = "main_course"
DESSERT = "dessert"
BEVERAGE = "beverage"
class FoodBase(BaseModel): class FoodBase(BaseModel):
name: constr(min_length=1, max_length=100) = Field(..., description="Name of the food item") name: str = Field(..., description="Name of the food item")
description: Optional[str] = Field(None, description="Description of the food item") description: Optional[str] = Field(None, description="Description of the food item")
price: float = Field(..., gt=0, description="Price of the food item") price: float = Field(..., gt=0, description="Price of the food item")
category: FoodCategory = Field(..., description="Category of the food item") is_available: bool = Field(True, description="Availability status of the food item")
category: Optional[str] = Field(None, description="Category of the food item")
cuisine: Optional[str] = Field(None, description="Cuisine of the food item")
allergens: Optional[Union[list, dict]] = Field(None, description="Allergens present in the food item")
class FoodCreate(FoodBase): class FoodCreate(FoodBase):
pass pass
class FoodResponse(FoodBase): class FoodResponse(FoodBase):
id: int = Field(..., description="Unique identifier for the food item")
is_available: bool = Field(True, description="Availability status of the food item")
class Config: class Config:
schema_extra = { schema_extra = {
"example": { "example": {
"id": 1,
"name": "Margherita Pizza", "name": "Margherita Pizza",
"description": "Classic Italian pizza with tomato sauce, mozzarella, and fresh basil", "description": "Classic Italian pizza with tomato sauce, mozzarella cheese, and fresh basil",
"price": 12.99, "price": 12.99,
"category": "main_course", "is_available": True,
"is_available": True "category": "Pizza",
"cuisine": "Italian",
"allergens": ["dairy", "wheat"]
} }
} }