Automated Action 34f86c8479 Add task completion tracking with timestamps
- Added completion_date field to Todo model
- Modified CRUD to auto-set completion_date when task is marked complete
- Added completion date stats (last 24h, last week metrics)
- Created Alembic migration for the new field
- Updated API documentation and README

generated with BackendIM... (backend.im)
2025-05-13 04:07:40 +00:00

150 lines
4.5 KiB
Markdown

# Simple Todo Application - FastAPI
A simple Todo API application built with FastAPI and SQLite. This RESTful API provides endpoints to create, read, update, and delete todo items with advanced organization features.
## Features
- RESTful API for Todo management
- CRUD operations for Todo items
- Todo categorization with categories
- Priority levels (low, medium, high)
- Due dates for task deadlines
- Task completion tracking with completion timestamps
- Advanced filtering capabilities:
- Filter by category
- Filter by priority
- Filter by completion status
- Filter by due date range
- Customizable sorting options
- Todo statistics and analytics including completion metrics
- SQLAlchemy ORM with SQLite database
- Alembic for database migrations
- FastAPI's automatic OpenAPI documentation
## Project Structure
```
simpletodoapplication/
├── alembic/ # Database migrations
│ ├── versions/ # Migration scripts
│ └── env.py # Alembic environment configuration
├── app/ # Application package
│ ├── api/ # API routes
│ │ └── routes/ # Route definitions
│ │ └── todos.py # Todo routes
│ ├── core/ # Core modules
│ │ └── config.py # Application configuration
│ ├── crud/ # CRUD operations
│ │ └── todo.py # Todo CRUD operations
│ ├── db/ # Database setup
│ │ └── base.py # Database connection
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ └── schemas/ # Pydantic schemas
│ └── todo.py # Todo schemas
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
```
## API Endpoints
### Todo Operations
- **GET /api/v1/todos/** - Get all todos with filtering options
- **POST /api/v1/todos/** - Create a new todo
- **GET /api/v1/todos/{todo_id}** - Get a specific todo
- **PUT /api/v1/todos/{todo_id}** - Update a todo
- **DELETE /api/v1/todos/{todo_id}** - Delete a todo
### Statistics
- **GET /api/v1/todos/stats** - Get todo statistics and analytics
### System
- **GET /health** - Health check endpoint
- **GET /docs** - API documentation (Swagger UI)
- **GET /redoc** - Alternative API documentation (ReDoc)
## Filtering and Sorting
The GET /api/v1/todos/ endpoint supports the following query parameters:
- **category** - Filter todos by category
- **priority** - Filter by priority level (low, medium, high)
- **completed** - Filter by completion status (true/false)
- **due_before** - Filter todos due before a specific date
- **due_after** - Filter todos due after a specific date
- **sort_by** - Sort by any todo field (default: created_at)
- **sort_desc** - Sort in descending order (default: true)
- **skip** - Number of records to skip (for pagination)
- **limit** - Maximum number of records to return (for pagination)
## Setup and Running
1. Install dependencies:
```
pip install -r requirements.txt
```
2. Apply migrations:
```
alembic upgrade head
```
3. Run the application:
```
uvicorn main:app --reload
```
4. Access the API documentation at:
```
http://localhost:8000/docs
```
## Todo Object Structure
```json
{
"id": 1,
"title": "Sample Todo",
"description": "This is a sample todo item",
"completed": false,
"category": "work",
"priority": "high",
"due_date": "2025-05-20T12:00:00",
"completion_date": null,
"created_at": "2025-05-13T12:00:00",
"updated_at": null
}
```
When a todo is marked as completed, the `completion_date` is automatically set to the current time. If a todo is marked as not completed, the `completion_date` is cleared.
## Statistics
The /api/v1/todos/stats endpoint returns the following information:
```json
{
"total": 10,
"completed": 3,
"incomplete": 7,
"overdue": 2,
"completed_last_24h": 1,
"completed_last_week": 3,
"by_category": {
"work": 4,
"personal": 3,
"shopping": 2,
"uncategorized": 1
},
"by_priority": {
"high": 3,
"medium": 5,
"low": 2
}
}
```
The statistics include:
- `completed_last_24h`: Number of tasks completed within the last 24 hours
- `completed_last_week`: Number of tasks completed within the last 7 days