Automated Action 1349113fe0 Create FastAPI REST API with SQLite
Features:
- Project structure setup
- Database configuration with SQLAlchemy
- Item model and CRUD operations
- API endpoints for items
- Alembic migrations
- Health check endpoint
- Comprehensive documentation

generated with BackendIM... (backend.im)
2025-05-14 00:49:31 +00:00

30 lines
1.0 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
class ItemBase(BaseModel):
name: str = Field(..., min_length=1, max_length=100, example="Example Item")
description: Optional[str] = Field(None, example="This is an example item description")
price: int = Field(..., gt=0, example=1999) # Price in cents (e.g., 19.99 USD = 1999)
is_active: bool = Field(True, example=True)
class ItemCreate(ItemBase):
pass
class ItemUpdate(BaseModel):
name: Optional[str] = Field(None, min_length=1, max_length=100, example="Updated Item")
description: Optional[str] = Field(None, example="This is an updated description")
price: Optional[int] = Field(None, gt=0, example=2499)
is_active: Optional[bool] = Field(None, example=True)
class ItemInDB(ItemBase):
id: int
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
from_attributes = True
class ItemResponse(ItemInDB):
"""Response model for items"""
pass