Skip to content

Conversation

Copy link

Copilot AI commented Oct 4, 2025

Summary

This PR implements priority levels, due dates, and filtering/sorting capabilities for the Todo API, transforming it from a basic demo into a production-ready task management backend.

Features Added

🎯 Priority Levels

Todos now support three priority levels with automatic validation:

  • High - Urgent tasks requiring immediate attention
  • Medium - Default priority for standard tasks
  • Low - Nice-to-have tasks
class Todo(BaseModel):
    priority: Optional[str] = Field(default="medium", pattern="^(low|medium|high)$")
    due_date: Optional[datetime] = None

📅 Due Dates

Todos can have optional deadlines in ISO 8601 format (YYYY-MM-DDTHH:MM:SS), enabling time-based task organization.

🔍 Advanced Filtering & Sorting

The GET /todos endpoint now supports powerful query parameters:

Filtering:

  • completed - Filter by completion status (true/false)
  • priority - Filter by priority level (low/medium/high)
  • before - Show tasks due before a specific date
  • after - Show tasks due after a specific date

Sorting:

  • sort=due_date - Sort by deadline (earliest first, null values last)
  • sort=priority - Sort by importance (high → medium → low)

Combined Queries:

# Get all high-priority incomplete tasks due within the next week, sorted by deadline
GET /todos?priority=high&completed=false&before=2025-10-15T00:00:00&sort=due_date

Example Usage

Create a High-Priority Todo with Deadline

curl -X POST http://localhost:8000/todos \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "title": "Submit report",
    "description": "Monthly project update",
    "completed": false,
    "priority": "high",
    "due_date": "2025-10-08T17:00:00"
  }'

Response:

{
  "id": 1,
  "title": "Submit report",
  "description": "Monthly project update",
  "completed": false,
  "priority": "high",
  "due_date": "2025-10-08T17:00:00"
}

Filter and Sort Tasks

# Get high-priority tasks due before Oct 15, sorted by due date
curl -X GET 'http://localhost:8000/todos?priority=high&before=2025-10-15T00:00:00&sort=due_date'

# Get all completed tasks
curl -X GET 'http://localhost:8000/todos?completed=true'

# Sort all tasks by priority
curl -X GET 'http://localhost:8000/todos?sort=priority'

Implementation Details

Changes Made

  • main.py (34 lines added):

    • Enhanced Todo model with priority and due_date fields
    • Added filtering and sorting logic to GET /todos endpoint
    • Updated PUT /todos/{id} to support priority and due_date updates
  • README.md (53 lines added):

    • Updated Features section with new capabilities
    • Enhanced API documentation with query parameter descriptions
    • Added 10 comprehensive cURL examples

Total: 83 lines changed across 2 files

Key Features

  • Backward Compatible - All existing functionality remains unchanged
  • Input Validation - Pydantic patterns ensure data integrity (invalid priorities are rejected)
  • Auto-Generated Docs - Swagger UI at /docs automatically shows all new parameters
  • No New Dependencies - Uses only existing FastAPI/Pydantic features
  • Clean Implementation - Follows existing code patterns and conventions

Testing

All features have been thoroughly tested:

  • ✅ Create/update todos with priority and due dates
  • ✅ Default priority ("medium") applied automatically
  • ✅ Filter by completion, priority, and date ranges
  • ✅ Sort by due_date and priority
  • ✅ Combined filtering and sorting
  • ✅ Input validation (rejects invalid priority values)

Benefits

This enhancement enables:

  • 📊 Better Task Organization - Organize work by urgency and importance
  • Deadline Tracking - Never miss important due dates
  • 🔎 Powerful Queries - Find exactly the tasks you need
  • 🎯 Production Readiness - Real-world task management capabilities
  • 📚 API Demo - Excellent showcase of FastAPI's query parameter features

Fixes

Closes #[issue_number] - Implements the complete feature specification including:

  • Priority levels (low/medium/high)
  • Due dates with ISO 8601 format
  • Filtering by completion, priority, and date ranges
  • Sorting by priority or due_date
  • Updated interactive API documentation
  • Comprehensive examples and testing
Original prompt

This section details on the original issue you should resolve

<issue_title>Feature Proposal: Todo Priorities, Deadlines & Filtering</issue_title>
<issue_description>

Feature Proposal: Todo Priorities, Deadlines & Filtering

Labels: enhancement feature backend frontend api
Milestone: v0.2 (proposed)


Summary

Add priority levels, due dates, and filtering/sorting capabilities to the existing FastAPI Todo backend. This will turn the demo into a more realistic, production-ready task tracker where users can manage importance and deadlines effectively.


Why

Currently, each todo item only supports title, description, and completed. Adding deadlines and priorities allows:

  • Task organization by urgency.

  • Improved API demonstrations with query parameters.

  • Easier extension into a frontend or team dashboard.


<h2 style="font-style: normal; font-variant-caps: normal; letter-spacing: normal; ...

Fixes #1

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 4, 2025 05:30
Co-authored-by: hoangsonww <124531104+hoangsonww@users.noreply.github.com>
…ation

Co-authored-by: hoangsonww <124531104+hoangsonww@users.noreply.github.com>
Copilot AI changed the title [WIP] Feature Proposal: Todo Priorities, Deadlines & Filtering Add Todo Priorities, Deadlines & Filtering to FastAPI Backend Oct 4, 2025
Copilot AI requested a review from hoangsonww October 4, 2025 05:36
Copilot finished work on behalf of hoangsonww October 4, 2025 05:36
@hoangsonww hoangsonww marked this pull request as ready for review October 6, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Proposal: Todo Priorities, Deadlines & Filtering

2 participants