
- Created project structure with FastAPI setup - Added SQLite database connection with SQLAlchemy ORM - Implemented Todo model and schemas - Added CRUD operations for Todo items - Created API endpoints for Todo management - Added health check endpoint - Configured Alembic for database migrations - Updated project documentation in README.md
24 lines
909 B
Python
24 lines
909 B
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.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) -> Optional[Todo]:
|
|
"""Get a todo by title"""
|
|
return db.query(Todo).filter(Todo.title == title).first()
|
|
|
|
def get_completed(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Todo]:
|
|
"""Get all completed todos"""
|
|
return db.query(Todo).filter(Todo.completed.is_(True)).offset(skip).limit(limit).all()
|
|
|
|
def get_incomplete(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Todo]:
|
|
"""Get all incomplete todos"""
|
|
return db.query(Todo).filter(Todo.completed.is_(False)).offset(skip).limit(limit).all()
|
|
|
|
|
|
todo = CRUDTodo(Todo) |