From 5f4f59fc6302a4e44773d4a939ae7b3304d61f1f Mon Sep 17 00:00:00 2001 From: Claude Agent Date: Wed, 18 Mar 2026 10:09:41 +0000 Subject: 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 --- internal/handlers/handlers.go | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) (limited to 'internal/handlers/handlers.go') 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) -- cgit v1.2.3