
Implemented a complete FastAPI backend with: - Project structure with FastAPI and SQLAlchemy - SQLite database with proper configuration - Alembic for database migrations - Generic Item resource with CRUD operations - REST API endpoints with proper validation - Health check endpoint - Documentation and setup instructions
45 lines
867 B
Python
45 lines
867 B
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# Shared properties
|
|
class ItemBase(BaseModel):
|
|
title: Optional[str] = None
|
|
description: Optional[str] = None
|
|
is_active: Optional[bool] = True
|
|
|
|
|
|
# Properties to receive on item creation
|
|
class ItemCreate(ItemBase):
|
|
title: str = Field(..., min_length=1, max_length=100)
|
|
|
|
|
|
# Properties to receive on item update
|
|
class ItemUpdate(ItemBase):
|
|
pass
|
|
|
|
|
|
# Properties shared by models stored in DB
|
|
class ItemInDBBase(ItemBase):
|
|
id: int
|
|
title: str
|
|
description: Optional[str] = None
|
|
is_active: bool
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
# Properties to return to client
|
|
class Item(ItemInDBBase):
|
|
pass
|
|
|
|
|
|
# Properties stored in DB
|
|
class ItemInDB(ItemInDBBase):
|
|
pass
|