113 lines
2.9 KiB
Markdown
113 lines
2.9 KiB
Markdown
# Simple Todo API
|
|
|
|
A deadass simple Todo API built with FastAPI and SQLite. This project provides a RESTful API for managing todo items with the basic CRUD operations.
|
|
|
|
## Features
|
|
|
|
- RESTful API endpoints for Todo resource (Create, Read, Update, Delete)
|
|
- Advanced filtering, sorting, and pagination capabilities
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- Health check endpoint
|
|
- Interactive API documentation (Swagger & ReDoc)
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
simpletodoapi/
|
|
├── alembic.ini
|
|
├── app/
|
|
│ ├── api/
|
|
│ │ ├── endpoints/
|
|
│ │ │ ├── health.py
|
|
│ │ │ └── todo.py
|
|
│ │ └── __init__.py
|
|
│ ├── core/
|
|
│ │ └── __init__.py
|
|
│ ├── db/
|
|
│ │ ├── database.py
|
|
│ │ └── __init__.py
|
|
│ ├── models/
|
|
│ │ ├── todo.py
|
|
│ │ └── __init__.py
|
|
│ ├── schemas/
|
|
│ │ ├── todo.py
|
|
│ │ └── __init__.py
|
|
│ └── __init__.py
|
|
├── migrations/
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ ├── versions/
|
|
│ │ ├── 20231111_initial_migration.py
|
|
│ │ └── __init__.py
|
|
│ └── __init__.py
|
|
├── main.py
|
|
└── requirements.txt
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Clone the repository
|
|
|
|
2. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at http://localhost:8000
|
|
|
|
## API Endpoints
|
|
|
|
### Health Check
|
|
- `GET /health` - Check API and database health
|
|
|
|
### Todo Management
|
|
- `GET /api/v1/todos` - Get all todos (with advanced filtering, sorting, and pagination)
|
|
- Filtering options:
|
|
- `completed`: Filter by completion status (true/false)
|
|
- `created_after`: Filter todos created on or after date (YYYY-MM-DD)
|
|
- `created_before`: Filter todos created on or before date (YYYY-MM-DD)
|
|
- Sorting options:
|
|
- `sort_by`: Field to sort by (id, title, created_at, updated_at)
|
|
- `sort_order`: Sort direction (asc, desc)
|
|
- Pagination:
|
|
- `skip`: Number of items to skip
|
|
- `limit`: Maximum number of items to return
|
|
- `GET /api/v1/todos/{todo_id}` - Get a specific todo by ID
|
|
- `POST /api/v1/todos` - Create a new todo
|
|
- `PUT /api/v1/todos/{todo_id}` - Update an existing todo
|
|
- `DELETE /api/v1/todos/{todo_id}` - Delete a todo
|
|
|
|
## API Documentation
|
|
|
|
Interactive API documentation is available at:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## Database
|
|
|
|
The application uses SQLite as the database. The database file is stored at `/app/storage/db/db.sqlite`.
|
|
|
|
Database migrations are managed with Alembic. The initial migration is already included to set up the todos table.
|
|
|
|
## Development
|
|
|
|
To run the development server with hot-reload:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
To lint the codebase:
|
|
```bash
|
|
ruff check .
|
|
```
|
|
|
|
To auto-fix linting issues:
|
|
```bash
|
|
ruff check --fix .
|
|
``` |