Fetched async via /api/todos/count so it doesn't block page render. Badge hidden when count is zero. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
634 B
Python
31 lines
634 B
Python
from fastapi import APIRouter
|
|
from app.vikunja import create_task, delete_task, get_tasks, update_task
|
|
|
|
router = APIRouter(prefix="/todos", tags=["todos"])
|
|
|
|
|
|
@router.get("/count")
|
|
def count_todos():
|
|
tasks = get_tasks()
|
|
return {"open": sum(1 for t in tasks if not t.get("done"))}
|
|
|
|
|
|
@router.get("/")
|
|
def list_todos():
|
|
return get_tasks()
|
|
|
|
|
|
@router.post("/")
|
|
def create_todo(body: dict):
|
|
return create_task(body.get("title", ""))
|
|
|
|
|
|
@router.post("/{task_id}")
|
|
def update_todo(task_id: int, body: dict):
|
|
update_task(task_id, **body)
|
|
|
|
|
|
@router.delete("/{task_id}")
|
|
def delete_todo(task_id: int):
|
|
delete_task(task_id)
|