44 lines
960 B
Python
44 lines
960 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ItemBase(BaseModel):
|
|
"""Base schema for item data."""
|
|
|
|
name: str = Field(..., min_length=1, max_length=100, description="The item name")
|
|
description: Optional[str] = Field(None, description="The item description")
|
|
|
|
|
|
class ItemCreate(ItemBase):
|
|
"""Schema for creating a new item."""
|
|
|
|
pass
|
|
|
|
|
|
class ItemUpdate(BaseModel):
|
|
"""Schema for updating an existing item."""
|
|
|
|
name: Optional[str] = Field(
|
|
None, min_length=1, max_length=100, description="The item name"
|
|
)
|
|
description: Optional[str] = Field(None, description="The item description")
|
|
|
|
|
|
class ItemInDB(ItemBase):
|
|
"""Schema for item as stored in the database."""
|
|
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class Item(ItemInDB):
|
|
"""Schema for item returned to clients."""
|
|
|
|
pass
|