MCPcopy Create free account
hub / github.com/astercloud/aster / handleTodoCreate

Method handleTodoCreate

server/handlers/websocket.go:554–633  ·  view source on GitHub ↗

handleTodoCreate handles todo creation

(wsConn *WebSocketConnection, payload map[string]any)

Source from the content-addressed store, hash-verified

552
553// handleTodoCreate handles todo creation
554func (h *WebSocketHandler) handleTodoCreate(wsConn *WebSocketConnection, payload map[string]any) {
555 listName := "default"
556 if name, ok := payload["list_name"].(string); ok && name != "" {
557 listName = name
558 }
559
560 todoData, ok := payload["todo"].(map[string]any)
561 if !ok {
562 h.sendError(wsConn, "invalid_todo", "todo data is required")
563 return
564 }
565
566 // 加载现有任务列表
567 todoList, err := h.todoManager.LoadTodoList(listName)
568 if err != nil {
569 // 创建新的任务列表
570 todoList = &builtin.TodoList{
571 ID: fmt.Sprintf("list_%s_%d", listName, time.Now().UnixNano()),
572 Name: listName,
573 Todos: []builtin.TodoItem{},
574 CreatedAt: time.Now(),
575 UpdatedAt: time.Now(),
576 Metadata: make(map[string]any),
577 }
578 }
579
580 // 创建新的 TodoItem
581 todo := builtin.TodoItem{
582 ID: fmt.Sprintf("todo_%d", time.Now().UnixNano()),
583 CreatedAt: time.Now(),
584 UpdatedAt: time.Now(),
585 Metadata: make(map[string]any),
586 }
587
588 if content, ok := todoData["content"].(string); ok {
589 todo.Content = content
590 }
591 if completed, ok := todoData["completed"].(bool); ok {
592 todo.Status = "pending"
593 if completed {
594 todo.Status = "completed"
595 now := time.Now()
596 todo.CompletedAt = &now
597 }
598 todo.ActiveForm = "任务完成"
599 } else {
600 todo.Status = "pending"
601 todo.ActiveForm = "进行中"
602 }
603 if priority, ok := todoData["priority"].(string); ok {
604 switch priority {
605 case "high":
606 todo.Priority = 3
607 case "medium":
608 todo.Priority = 2
609 case "low":
610 todo.Priority = 1
611 default:

Callers 1

handleMessageMethod · 0.95

Calls 4

sendErrorMethod · 0.95
broadcastToAllMethod · 0.95
LoadTodoListMethod · 0.65
StoreTodoListMethod · 0.65

Tested by

no test coverage detected