
- Add User model with email-based authentication - Add Tag model with many-to-many relationship to todos - Add TodoTag junction table for todo-tag relationships - Enhance Todo model with priority levels (low, medium, high) - Add due_date field with datetime support - Add recurrence_pattern field for recurring todos - Add parent-child relationship for subtasks support - Create comprehensive alembic migration for all changes - Add proper indexes for performance optimization - Use Text type for todo descriptions - Implement proper SQLAlchemy relationships and foreign keys
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
from fastapi import FastAPI, Depends, HTTPException
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from enum import Enum
|
|
|
|
from app.db.base import engine, Base
|
|
from app.db.session import get_db
|
|
from app import crud, schemas
|
|
|
|
# Priority levels enum
|
|
class Priority(str, Enum):
|
|
LOW = "low"
|
|
MEDIUM = "medium"
|
|
HIGH = "high"
|
|
URGENT = "urgent"
|
|
|
|
# Create database tables
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
app = FastAPI(
|
|
title="Enhanced Todo App API",
|
|
description="A comprehensive todo application API with categories, priorities, due dates, subtasks, users, and recurring todos",
|
|
version="2.0.0",
|
|
openapi_url="/openapi.json"
|
|
)
|
|
|
|
# CORS configuration
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {
|
|
"title": "Enhanced Todo App API",
|
|
"version": "2.0.0",
|
|
"documentation": "/docs",
|
|
"redoc": "/redoc",
|
|
"openapi": "/openapi.json",
|
|
"health": "/health"
|
|
}
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "healthy"}
|
|
|
|
@app.post("/todos/", response_model=schemas.Todo)
|
|
def create_todo(todo: schemas.TodoCreate, db: Session = Depends(get_db)):
|
|
return crud.create_todo(db=db, todo=todo)
|
|
|
|
@app.get("/todos/", response_model=List[schemas.Todo])
|
|
def read_todos(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
todos = crud.get_todos(db, skip=skip, limit=limit)
|
|
return todos
|
|
|
|
@app.get("/todos/{todo_id}", response_model=schemas.Todo)
|
|
def read_todo(todo_id: int, db: Session = Depends(get_db)):
|
|
db_todo = crud.get_todo(db, todo_id=todo_id)
|
|
if db_todo is None:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return db_todo
|
|
|
|
@app.put("/todos/{todo_id}", response_model=schemas.Todo)
|
|
def update_todo(todo_id: int, todo: schemas.TodoUpdate, db: Session = Depends(get_db)):
|
|
db_todo = crud.update_todo(db, todo_id=todo_id, todo_update=todo)
|
|
if db_todo is None:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return db_todo
|
|
|
|
@app.delete("/todos/{todo_id}", response_model=schemas.Todo)
|
|
def delete_todo(todo_id: int, db: Session = Depends(get_db)):
|
|
db_todo = crud.delete_todo(db, todo_id=todo_id)
|
|
if db_todo is None:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return db_todo
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000) |