Automated Action a00c823bd1 Add search functionality to find todos by title or description
- Add search parameter to get_todos CRUD function
- Add search parameter to main todos endpoint
- Create dedicated /search endpoint for title/description search
- Update README with new search functionality
- Fix datetime import issue in todo_stats function

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

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
  • Search functionality to find todos by title or description content
  • 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/search - Search todos by title or description content
  • 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:

  • search - Search within title and description fields
  • 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)

The GET /api/v1/todos/search endpoint requires the following parameter:

  • q - Search query string (required) - searches in both title and description fields

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

{
  "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:

{
  "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
Description
Project: Simple Todo Application
Readme 56 KiB
Languages
Python 97.3%
Mako 2.7%