From 577d40634b46db726049858dc0ef062d3990c251 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 15:59:14 +0000 Subject: [PATCH] Add Food schema --- schemas/food.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/schemas/food.py b/schemas/food.py index 9ceffda..3cd212f 100644 --- a/schemas/food.py +++ b/schemas/food.py @@ -1,28 +1,38 @@ from pydantic import BaseModel, Field -from typing import Optional, Union +from typing import Optional +from uuid import UUID +# Base schema class FoodBase(BaseModel): name: str = Field(..., description="Name 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") - 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") + category_id: UUID = Field(..., description="ID of the food category") +# Schema for creating a new Food class FoodCreate(FoodBase): - pass - -class FoodResponse(FoodBase): class Config: schema_extra = { "example": { - "name": "Margherita Pizza", - "description": "Classic Italian pizza with tomato sauce, mozzarella cheese, and fresh basil", + "name": "Pizza Margherita", + "description": "Classic Italian pizza with tomato sauce, mozzarella, and basil", "price": 12.99, - "is_available": True, - "category": "Pizza", - "cuisine": "Italian", - "allergens": ["dairy", "wheat"] + "category_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6" + } + } + +# Schema for Food responses +class Food(FoodBase): + id: UUID + + class Config: + orm_mode = True + schema_extra = { + "example": { + "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", + "name": "Pizza Margherita", + "description": "Classic Italian pizza with tomato sauce, mozzarella, and basil", + "price": 12.99, + "category_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6" } } \ No newline at end of file