diff options
Diffstat (limited to 'internal/handlers/handlers.go')
| -rw-r--r-- | internal/handlers/handlers.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 9ba6351..b3bc8e4 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -672,3 +672,58 @@ func (h *Handler) HandleCompleteTask(w http.ResponseWriter, r *http.Request) { // Return empty response (task will be removed from DOM) w.WriteHeader(http.StatusOK) } + +// HandleCompleteAtom handles completion of a unified task (Atom) +func (h *Handler) HandleCompleteAtom(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + if err := r.ParseForm(); err != nil { + http.Error(w, "Failed to parse form", http.StatusBadRequest) + log.Printf("Error parsing form: %v", err) + return + } + + id := r.FormValue("id") + source := r.FormValue("source") + + if id == "" || source == "" { + http.Error(w, "Missing id or source", http.StatusBadRequest) + return + } + + var err error + switch source { + case "todoist": + err = h.todoistClient.CompleteTask(ctx, id) + case "trello": + // Archive the card (closed = true) + updates := map[string]interface{}{ + "closed": true, + } + err = h.trelloClient.UpdateCard(ctx, id, updates) + default: + http.Error(w, "Unknown source: "+source, http.StatusBadRequest) + return + } + + if err != nil { + http.Error(w, "Failed to complete task", http.StatusInternalServerError) + log.Printf("Error completing atom (source=%s, id=%s): %v", source, id, err) + return + } + + // Remove from local cache + switch source { + case "todoist": + if err := h.store.DeleteTask(id); err != nil { + log.Printf("Warning: failed to delete task from cache: %v", err) + } + case "trello": + if err := h.store.DeleteCard(id); err != nil { + log.Printf("Warning: failed to delete card from cache: %v", err) + } + } + + // Return 200 OK with empty body to remove the element from DOM + w.WriteHeader(http.StatusOK) +} |
