38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
from pydantic import BaseModel, Field
|
|
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")
|
|
category_id: UUID = Field(..., description="ID of the food category")
|
|
|
|
# Schema for creating a new Food
|
|
class FoodCreate(FoodBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Pizza Margherita",
|
|
"description": "Classic Italian pizza with tomato sauce, mozzarella, and basil",
|
|
"price": 12.99,
|
|
"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"
|
|
}
|
|
} |