summaryrefslogtreecommitdiff
path: root/internal/handlers/helpers.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-01-26 08:10:27 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-01-26 08:10:27 -1000
commit2e739638477e87a1b1df662740f191c86db60186 (patch)
tree302916e1e0c99ae47213128fa79133752203a271 /internal/handlers/helpers.go
parentaff60af8ba24c8d5330c706ddf26927d81436d79 (diff)
Phase 5: Extract functions to reduce complexity
- Create atoms.go with BuildUnifiedAtomList, SortAtomsByUrgency, PartitionAtomsByTime - Create helpers.go with parseFormOr400, requireFormValue - Refactor HandleTabTasks from 95 lines to 25 lines using extracted functions - Remove duplicate atomUrgencyTier function - Update handlers to use parseFormOr400 helper Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/helpers.go')
-rw-r--r--internal/handlers/helpers.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/handlers/helpers.go b/internal/handlers/helpers.go
new file mode 100644
index 0000000..e67eea7
--- /dev/null
+++ b/internal/handlers/helpers.go
@@ -0,0 +1,26 @@
+package handlers
+
+import (
+ "net/http"
+)
+
+// parseFormOr400 parses the request form and returns false if parsing fails
+// (after writing a 400 error response). Returns true if parsing succeeds.
+func parseFormOr400(w http.ResponseWriter, r *http.Request) bool {
+ if err := r.ParseForm(); err != nil {
+ JSONError(w, http.StatusBadRequest, "Failed to parse form", err)
+ return false
+ }
+ return true
+}
+
+// requireFormValue returns the form value for the given key, or writes a 400 error
+// and returns empty string if the value is missing.
+func requireFormValue(w http.ResponseWriter, r *http.Request, key string) (string, bool) {
+ value := r.FormValue(key)
+ if value == "" {
+ JSONError(w, http.StatusBadRequest, "Missing required field: "+key, nil)
+ return "", false
+ }
+ return value, true
+}