diff options
| author | Claude Agent <agent@workspace> | 2026-03-18 10:09:41 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-19 00:11:16 +0000 |
| commit | 5f4f59fc6302a4e44773d4a939ae7b3304d61f1f (patch) | |
| tree | 1474e5232d5a8949e315104cbe1300baf10fcab8 /internal/handlers/handlers.go | |
| parent | 5723d6635f9462e60960b0f9548273d95a86d8f3 (diff) | |
refactor: RF-04/08 migrate inline HTML to templates, standardize form parsing
RF-04: Already complete in codebase (handlers use HTMLResponse + partials).
RF-08: Migrate single-required-field handlers from Pattern A/B to Pattern C
(requireFormValue). Affected: HandleCompleteTask, HandleCompleteCard,
HandleReportBug, HandleCreateTask in handlers.go; HandleToggleFeature,
HandleCreateFeature in settings.go. Reduces 6-8 lines of boilerplate to 2.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/handlers.go')
| -rw-r--r-- | internal/handlers/handlers.go | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index ce2c57e..d860595 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -514,13 +514,8 @@ func (h *Handler) HandleCreateCard(w http.ResponseWriter, r *http.Request) { // HandleCompleteCard marks a Trello card as complete func (h *Handler) HandleCompleteCard(w http.ResponseWriter, r *http.Request) { - if !parseFormOr400(w, r) { - return - } - - cardID := r.FormValue("card_id") - if cardID == "" { - JSONError(w, http.StatusBadRequest, "Missing card_id", nil) + cardID, ok := requireFormValue(w, r, "card_id") + if !ok { return } @@ -536,19 +531,12 @@ func (h *Handler) HandleCompleteCard(w http.ResponseWriter, r *http.Request) { func (h *Handler) HandleCreateTask(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - if err := r.ParseForm(); err != nil { - JSONError(w, http.StatusBadRequest, "Failed to parse form", err) + content, ok := requireFormValue(w, r, "content") + if !ok { return } - - content := r.FormValue("content") projectID := r.FormValue("project_id") - if content == "" { - JSONError(w, http.StatusBadRequest, "Missing content", nil) - return - } - if _, err := h.todoistClient.CreateTask(ctx, content, projectID, nil, 0); err != nil { JSONError(w, http.StatusInternalServerError, "Failed to create task", err) return @@ -572,14 +560,8 @@ func (h *Handler) HandleCreateTask(w http.ResponseWriter, r *http.Request) { // HandleCompleteTask marks a Todoist task as complete func (h *Handler) HandleCompleteTask(w http.ResponseWriter, r *http.Request) { - if err := r.ParseForm(); err != nil { - JSONError(w, http.StatusBadRequest, "Failed to parse form", err) - return - } - - taskID := r.FormValue("task_id") - if taskID == "" { - JSONError(w, http.StatusBadRequest, "Missing task_id", nil) + taskID, ok := requireFormValue(w, r, "task_id") + if !ok { return } @@ -829,15 +811,11 @@ func (h *Handler) HandleGetBugs(w http.ResponseWriter, r *http.Request) { // HandleReportBug saves a new bug report func (h *Handler) HandleReportBug(w http.ResponseWriter, r *http.Request) { - if !parseFormOr400(w, r) { - return - } - - description := strings.TrimSpace(r.FormValue("description")) - if description == "" { - JSONError(w, http.StatusBadRequest, "Description is required", nil) + description, ok := requireFormValue(w, r, "description") + if !ok { return } + description = strings.TrimSpace(description) if err := h.store.SaveBug(description); err != nil { JSONError(w, http.StatusInternalServerError, "Failed to save bug", err) |
