From 3722051240738fa5e51cc577f127fb524596f377 Mon Sep 17 00:00:00 2001 From: GargiGogulwar Date: Mon, 27 Jul 2026 13:10:39 +0530 Subject: [PATCH] Fix task bugs and add search filter --- app/service.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/service.py b/app/service.py index 8022b93..78cd739 100644 --- a/app/service.py +++ b/app/service.py @@ -12,13 +12,19 @@ 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": + # Filter by status + if status and task["status"] != status: continue - # Instructor note: partial feature for the lab. - # The route already accepts `q`, but search is not implemented yet. + # Case-insensitive search in title and description + if q: + search = q.lower() + if ( + search not in task["title"].lower() + and search not in task["description"].lower() + ): + continue + filtered.append(task) return filtered @@ -53,12 +59,11 @@ def complete_task(task_id: int) -> dict[str, Any] | None: for task in tasks: if task["id"] == task_id: - updated_task = dict(task) - updated_task["status"] = "done" - updated_task["completed_at"] = datetime.now(timezone.utc).isoformat() + task["status"] = "done" + task["completed_at"] = datetime.now(timezone.utc).isoformat() + + save_tasks(tasks) - # Instructor note: intentional bug for the lab. - # The updated task is returned, but the stored list is never updated or saved. - return updated_task + return task - return None + return None \ No newline at end of file