diff --git a/src/open_apps/apps/todo_app/main.py b/src/open_apps/apps/todo_app/main.py index 3e9567d..92a2252 100644 --- a/src/open_apps/apps/todo_app/main.py +++ b/src/open_apps/apps/todo_app/main.py @@ -173,8 +173,13 @@ def delete(id: int): @rt("/todo") -def post(todo: Todo): - return todos.insert(todo), mk_input(hx_swap_oob="true") +def post(title: str): + # 计算新待办ID:取现有最大id,无数据则从0开始自增 + new_id = max([t.id for t in todos()], default=-1) + 1 + # 插入新Todo对象,done默认未完成 + todos.upsert(Todo(id=new_id, title=title, done=False)) + # 返回最新插入的一条数据 + 前端刷新标记 + return todos[-1], mk_input(hx_swap_oob="true") @rt("/todo/edit/{id}")