
- Setup project structure with FastAPI - Create Todo model and database schemas - Implement CRUD operations for Todo items - Create API endpoints for Todo operations - Add health check endpoint - Configure Alembic for database migrations - Add detailed documentation in README.md
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.todo import Todo, TodoPriority
|
|
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 item by title.
|
|
"""
|
|
return db.execute(select(Todo).where(Todo.title == title)).scalars().first()
|
|
|
|
def get_by_priority(
|
|
self, db: Session, *, priority: TodoPriority, skip: int = 0, limit: int = 100
|
|
) -> List[Todo]:
|
|
"""
|
|
Get Todo items by priority level.
|
|
"""
|
|
statement = select(Todo).where(Todo.priority == priority).offset(skip).limit(limit)
|
|
return list(db.execute(statement).scalars().all())
|
|
|
|
def get_completed(
|
|
self, db: Session, *, completed: bool = True, skip: int = 0, limit: int = 100
|
|
) -> List[Todo]:
|
|
"""
|
|
Get completed or uncompleted Todo items.
|
|
"""
|
|
statement = select(Todo).where(Todo.completed == completed).offset(skip).limit(limit)
|
|
return list(db.execute(statement).scalars().all())
|
|
|
|
|
|
todo = CRUDTodo(Todo)
|