From ff3be0dc528fdf73e5ee68a62daa5f4a3f544e9f Mon Sep 17 00:00:00 2001 From: Arun Janardhanan Date: Tue, 18 Aug 2026 14:22:04 +0100 Subject: [PATCH] Fix task filters and completion persistence --- app/service.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/service.py b/app/service.py index 8022b93..9f7d2bb 100644 --- a/app/service.py +++ b/app/service.py @@ -10,15 +10,18 @@ def list_tasks(status: str | None = None, q: str | None = None) -> list[dict[str """Return task records, optionally filtered by status and search text.""" tasks = load_tasks() filtered: list[dict[str, Any]] = [] + query = q.lower() if q else None 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 - # Instructor note: partial feature for the lab. - # The route already accepts `q`, but search is not implemented yet. + if query: + title = task["title"].lower() + description = task["description"].lower() + if query not in title and query not in description: + continue + filtered.append(task) return filtered @@ -51,14 +54,14 @@ def complete_task(task_id: int) -> dict[str, Any] | None: """Mark a task as completed.""" tasks = load_tasks() - for task in tasks: + for index, 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[index] = updated_task + save_tasks(tasks) return updated_task return None