handleTodoUpdate handles todo updates
(wsConn *WebSocketConnection, payload map[string]any)
| 634 | |
| 635 | // handleTodoUpdate handles todo updates |
| 636 | func (h *WebSocketHandler) handleTodoUpdate(wsConn *WebSocketConnection, payload map[string]any) { |
| 637 | listName := "default" |
| 638 | if name, ok := payload["list_name"].(string); ok && name != "" { |
| 639 | listName = name |
| 640 | } |
| 641 | |
| 642 | todoData, ok := payload["todo"].(map[string]any) |
| 643 | if !ok { |
| 644 | h.sendError(wsConn, "invalid_todo", "todo data is required") |
| 645 | return |
| 646 | } |
| 647 | |
| 648 | todoID, ok := todoData["id"].(string) |
| 649 | if !ok { |
| 650 | h.sendError(wsConn, "missing_todo_id", "todo id is required") |
| 651 | return |
| 652 | } |
| 653 | |
| 654 | // 加载任务列表 |
| 655 | todoList, err := h.todoManager.LoadTodoList(listName) |
| 656 | if err != nil { |
| 657 | h.sendError(wsConn, "list_not_found", fmt.Sprintf("Todo list '%s' not found", listName)) |
| 658 | return |
| 659 | } |
| 660 | |
| 661 | // 查找并更新任务 |
| 662 | updated := false |
| 663 | for i, existingTodo := range todoList.Todos { |
| 664 | if existingTodo.ID == todoID { |
| 665 | // 更新字段 |
| 666 | if content, ok := todoData["content"].(string); ok { |
| 667 | todoList.Todos[i].Content = content |
| 668 | } |
| 669 | if completed, ok := todoData["completed"].(bool); ok { |
| 670 | wasCompleted := existingTodo.Status == "completed" |
| 671 | isCompleted := completed |
| 672 | |
| 673 | if isCompleted && !wasCompleted { |
| 674 | todoList.Todos[i].Status = "completed" |
| 675 | now := time.Now() |
| 676 | todoList.Todos[i].CompletedAt = &now |
| 677 | todoList.Todos[i].ActiveForm = "任务完成" |
| 678 | } else if !isCompleted && wasCompleted { |
| 679 | todoList.Todos[i].Status = "pending" |
| 680 | todoList.Todos[i].CompletedAt = nil |
| 681 | todoList.Todos[i].ActiveForm = "进行中" |
| 682 | } |
| 683 | } |
| 684 | if priority, ok := todoData["priority"].(string); ok { |
| 685 | switch priority { |
| 686 | case "high": |
| 687 | todoList.Todos[i].Priority = 3 |
| 688 | case "medium": |
| 689 | todoList.Todos[i].Priority = 2 |
| 690 | case "low": |
| 691 | todoList.Todos[i].Priority = 1 |
| 692 | default: |
| 693 | todoList.Todos[i].Priority = 0 |
no test coverage detected