
- Add parent_id field to Todo model with self-referential foreign key - Add parent/children relationships and is_subtask property - Update TodoCreate/TodoUpdate schemas to include parent_id - Add subtasks list to Todo schema and create SubtaskCreate schema - Enhance get_todos CRUD function with parent_id filtering - Add subtask-specific CRUD functions: get_subtasks, create_subtask, move_subtask - Add API endpoints for subtask management - Create migration for adding parent_id column - Update imports and fix circular dependencies - Ensure proper cycle prevention and validation Features added: - GET /todos/{todo_id}/subtasks - Get all subtasks for a todo - POST /todos/{todo_id}/subtasks - Create a new subtask - PUT /subtasks/{subtask_id}/move - Move subtask or convert to main todo - Query parameter parent_id for filtering by parent - Query parameter include_subtasks for excluding subtasks from main list
Simple Todo API
A simple todo application built with FastAPI and SQLite.
Features
- Create, read, update, and delete todos
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- FastAPI with automatic OpenAPI documentation
- CORS enabled for all origins
- Health check endpoint
API Endpoints
GET /
- Root endpoint with basic informationGET /health
- Health check endpointGET /docs
- Interactive API documentation (Swagger UI)GET /redoc
- Alternative API documentationGET /api/v1/todos
- Get all todosPOST /api/v1/todos
- Create a new todoGET /api/v1/todos/{todo_id}
- Get a specific todoPUT /api/v1/todos/{todo_id}
- Update a specific todoDELETE /api/v1/todos/{todo_id}
- Delete a specific todo
Installation
- Install the dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
Project Structure
├── app/
│ ├── api/
│ │ └── v1/
│ │ ├── __init__.py
│ │ └── todos.py
│ ├── crud/
│ │ ├── __init__.py
│ │ └── todo.py
│ ├── db/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ └── session.py
│ ├── models/
│ │ ├── __init__.py
│ │ └── todo.py
│ ├── schemas/
│ │ ├── __init__.py
│ │ └── todo.py
│ └── __init__.py
├── alembic/
│ ├── versions/
│ │ └── 001_initial_todo_table.py
│ ├── env.py
│ └── script.py.mako
├── alembic.ini
├── main.py
├── requirements.txt
└── README.md
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
. The database schema is managed using Alembic migrations.
Todo Model
Each todo has the following fields:
id
: Unique identifier (auto-generated)title
: Todo title (required, max 200 characters)description
: Todo description (optional, max 500 characters)completed
: Completion status (boolean, default: false)created_at
: Creation timestampupdated_at
: Last update timestamp
Languages
Python
99.2%
Mako
0.8%