
Features: - Project structure with FastAPI framework - SQLAlchemy models with SQLite database - Alembic migrations system - CRUD operations for items - API routers with endpoints for items - Health endpoint for monitoring - Error handling and validation - Comprehensive documentation
27 lines
724 B
Python
27 lines
724 B
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.item import Item
|
|
from app.schemas.item import ItemCreate, ItemUpdate
|
|
|
|
|
|
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
|
|
def get_by_title(self, db: Session, *, title: str) -> Optional[Item]:
|
|
return db.query(Item).filter(Item.title == title).first()
|
|
|
|
def get_multi_by_active(
|
|
self, db: Session, *, skip: int = 0, limit: int = 100, is_active: bool = True
|
|
) -> List[Item]:
|
|
return (
|
|
db.query(Item)
|
|
.filter(Item.is_active == is_active)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
item = CRUDItem(Item)
|