
- Set up project structure and FastAPI app - Create database models and SQLAlchemy connection - Implement Alembic migration scripts - Add CRUD API endpoints for Todo items - Add health check endpoint - Set up validation, error handling, and middleware - Add comprehensive documentation in README.md
33 lines
973 B
Python
33 lines
973 B
Python
from typing import List
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.db.crud.base import CRUDBase
|
|
from app.models.todo import Todo
|
|
from app.schemas.todo import TodoCreate, TodoUpdate
|
|
|
|
|
|
class CRUDTodo(CRUDBase[Todo, TodoCreate, TodoUpdate]):
|
|
def get_by_title(self, db: Session, *, title: str) -> List[Todo]:
|
|
return db.query(self.model).filter(self.model.title.contains(title)).all()
|
|
|
|
def get_completed(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Todo]:
|
|
return (
|
|
db.query(self.model)
|
|
.filter(self.model.completed.is_(True))
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
def get_uncompleted(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Todo]:
|
|
return (
|
|
db.query(self.model)
|
|
.filter(self.model.completed.is_(False))
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
todo = CRUDTodo(Todo) |