From bf6a662af438c380fd9df20d8443f1e037e86a0c Mon Sep 17 00:00:00 2001 From: 269564_nttds Date: Thu, 30 Jul 2026 15:57:16 +0530 Subject: [PATCH] Fix task bugs and add search filter - Fix status filter comparing against literal string instead of param value - Implement full-text search on title + description using q param - Fix complete_task not updating the task list or persisting the change - Mark task #3 as completed in seed data Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- app/service.py | 16 +++++++--------- data/tasks.json | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/service.py b/app/service.py index 8022b93..64227cb 100644 --- a/app/service.py +++ b/app/service.py @@ -12,13 +12,12 @@ def list_tasks(status: str | None = None, q: str | None = None) -> list[dict[str filtered: list[dict[str, Any]] = [] for task in tasks: - # Instructor note: intentional bug for the lab. - # This uses the literal string "status" instead of the query parameter value. - if status and task["status"] != "status": + if status and task["status"] != status: + continue + + if q and q.lower() not in (task["title"] + " " + task["description"]).lower(): continue - # Instructor note: partial feature for the lab. - # The route already accepts `q`, but search is not implemented yet. filtered.append(task) return filtered @@ -51,14 +50,13 @@ def complete_task(task_id: int) -> dict[str, Any] | None: """Mark a task as completed.""" tasks = load_tasks() - for task in tasks: + for i, task in enumerate(tasks): if task["id"] == task_id: updated_task = dict(task) updated_task["status"] = "done" updated_task["completed_at"] = datetime.now(timezone.utc).isoformat() - - # Instructor note: intentional bug for the lab. - # The updated task is returned, but the stored list is never updated or saved. + tasks[i] = updated_task + save_tasks(tasks) return updated_task return None diff --git a/data/tasks.json b/data/tasks.json index 8cc3396..8df56b0 100644 --- a/data/tasks.json +++ b/data/tasks.json @@ -21,10 +21,10 @@ "id": 3, "title": "Plan workshop agenda", "description": "Outline topics for the partner onboarding session.", - "status": "open", + "status": "done", "priority": "medium", "created_at": "2026-02-27T11:45:00+00:00", - "completed_at": null + "completed_at": "2026-07-30T10:17:31.659775+00:00" }, { "id": 4,