Add Pen schema

This commit is contained in:
Backend IM Bot 2025-03-26 23:08:20 +01:00
parent b29e0af639
commit 07a0980ee9

View File

@ -1,31 +1,26 @@
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
# Base schema
class PenBase(BaseModel): class PenBase(BaseModel):
name: str = Field(..., description="Name of the pen") name: str = Field(..., description="Name of the pen")
color: str = Field(..., description="Color of the pen") color: str = Field(..., description="Color of the pen")
brand: str = Field(..., description="Brand of the pen") brand: str = Field(..., description="Brand of the pen")
price: int = Field(..., gt=0, description="Price of the pen") price: int = Field(..., gt=0, description="Price of the pen")
stock: int = Field(..., ge=0, description="Stock quantity of the pen")
class Config: class Config:
schema_extra = { schema_extra = {
"example": { "example": {
"name": "Classic Pen", "name": "BIC Cristal",
"color": "Blue", "color": "Blue",
"brand": "PenBrand", "brand": "BIC",
"price": 5, "price": 2
"stock": 100
} }
} }
# Schema for creating a new Pen
class PenCreate(PenBase): class PenCreate(PenBase):
pass pass
# Schema for Pen responses class PenResponse(PenBase):
class Pen(PenBase): id: int
id: int = Field(..., description="Unique identifier for the pen")
class Config: class Config:
orm_mode = True orm_mode = True