Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ 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]] = []
search_term = q.casefold() 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 search_term and search_term not in (
f'{task["title"]} {task["description"]}'.casefold()
):
continue

# Instructor note: partial feature for the lab.
# The route already accepts `q`, but search is not implemented yet.
filtered.append(task)

return filtered
Expand Down Expand Up @@ -56,9 +58,8 @@ def complete_task(task_id: int) -> dict[str, Any] | None:
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[tasks.index(task)] = updated_task
save_tasks(tasks)
return updated_task

return None