Add Food schema

This commit is contained in:
Backend IM Bot 2025-03-28 16:01:01 +00:00
parent 2102e1d855
commit b938114f33

View File

@ -1,38 +1,18 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from typing import Optional
from uuid import UUID from uuid import UUID
# Base schema
class FoodBase(BaseModel): class FoodBase(BaseModel):
name: str = 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") address: str = Field(..., description="Address of the restaurant")
price: float = Field(..., gt=0, description="Price of the food item") description: str | None = Field(None, description="Description of the food item")
category_id: UUID = Field(..., description="ID of the food category") price: float = Field(..., description="Price of the food item")
restaurant_id: UUID = Field(..., description="ID of the restaurant")
# Schema for creating a new Food
class FoodCreate(FoodBase): class FoodCreate(FoodBase):
class Config: pass
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 FoodResponse(FoodBase):
class Food(FoodBase): id: UUID = Field(..., description="ID of the food item")
id: UUID
class Config: class Config:
orm_mode = True 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"
}
}