handlers.py•681 B
import uuid
from typing import Optional
DATASTORE = {}
def add_task(title: str, content: str, due_date: Optional[str] = None):
if not title or not content:
raise ValueError("title and content are required")
new_id = str(uuid.uuid4())
task = {
"task_id": new_id,
"title": title,
"content": content,
"due_date": due_date or "",
"done": False,
}
DATASTORE[new_id] = task
return task
def list_tasks():
return list(DATASTORE.values())
def complete_task(task_id):
task = DATASTORE.get(task_id)
if not task:
return {"error": "Task does not exist"}
task["done"] = True
return task