From 354f9cf9491d6ca3e181ce95d2f41295b478707d Mon Sep 17 00:00:00 2001 From: AntonKruhlou <113982699+AntonKruhlou@users.noreply.github.com> Date: Sat, 5 Sep 2026 13:40:06 +0300 Subject: [PATCH] Fix task bugs and add search filter --- app/service.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/service.py b/app/service.py index 8022b93..8453465 100644 --- a/app/service.py +++ b/app/service.py @@ -11,14 +11,15 @@ def list_tasks(status: str | None = None, q: str | None = None) -> list[dict[str 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 + + if query and query not in task["title"].lower() and query not in 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 +52,13 @@ 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