Add Meal schema

This commit is contained in:
Backend IM Bot 2025-03-28 09:41:22 +00:00
parent 4d31e63cb8
commit df5a735b42

View File

@ -1,18 +1,33 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field, validator
from typing import Optional from typing import Optional, Union
from uuid import UUID
class MealBase(BaseModel): class MealBase(BaseModel):
name: str = Field(..., description="Name of the meal") name: str = Field(..., description="Name of the meal")
description: Optional[str] = Field(None, description="Description of the meal") description: Optional[str] = Field(None, description="Description of the meal")
price: float = Field(..., gt=0, description="Price of the meal") price: float = Field(..., gt=0, description="Price of the meal")
category_id: UUID = Field(..., description="ID of the category the meal belongs to") is_available: bool = Field(True, description="Availability status of the meal")
category: Optional[str] = Field(None, description="Category of the meal")
cuisine: Optional[str] = Field(None, description="Cuisine of the meal")
dietary_restrictions: Optional[dict] = Field(None, description="Dietary restrictions for the meal")
class Config:
schema_extra = {
"example": {
"name": "Margherita Pizza",
"description": "Classic Italian pizza with tomato sauce, mozzarella cheese, and fresh basil",
"price": 12.99,
"is_available": True,
"category": "Pizza",
"cuisine": "Italian",
"dietary_restrictions": {"vegetarian": True, "nut_free": True}
}
}
class MealCreate(MealBase): class MealCreate(MealBase):
pass pass
class MealResponse(MealBase): class MealResponse(MealBase):
id: UUID = Field(..., description="ID of the meal") id: int = Field(..., description="Unique identifier for the meal")
class Config: class Config:
orm_mode = True orm_mode = True