summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/handlers/handlers.go40
-rw-r--r--internal/handlers/settings.go22
2 files changed, 13 insertions, 49 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)
diff --git a/internal/handlers/settings.go b/internal/handlers/settings.go
index c0ba654..a780170 100644
--- a/internal/handlers/settings.go
+++ b/internal/handlers/settings.go
@@ -196,19 +196,12 @@ func (h *Handler) HandleGetSourceOptions(w http.ResponseWriter, r *http.Request)
// HandleToggleFeature toggles a feature flag
func (h *Handler) HandleToggleFeature(w http.ResponseWriter, r *http.Request) {
- if err := r.ParseForm(); err != nil {
- JSONError(w, http.StatusBadRequest, "Failed to parse form", err)
+ name, ok := requireFormValue(w, r, "name")
+ if !ok {
return
}
-
- name := r.FormValue("name")
enabled := r.FormValue("enabled") == "true"
- if name == "" {
- JSONError(w, http.StatusBadRequest, "Feature name required", nil)
- return
- }
-
if err := h.store.SetFeatureEnabled(name, enabled); err != nil {
JSONError(w, http.StatusInternalServerError, "Failed to update feature", err)
return
@@ -220,19 +213,12 @@ func (h *Handler) HandleToggleFeature(w http.ResponseWriter, r *http.Request) {
// HandleCreateFeature creates a new feature toggle
func (h *Handler) HandleCreateFeature(w http.ResponseWriter, r *http.Request) {
- if err := r.ParseForm(); err != nil {
- JSONError(w, http.StatusBadRequest, "Failed to parse form", err)
+ name, ok := requireFormValue(w, r, "name")
+ if !ok {
return
}
-
- name := r.FormValue("name")
description := r.FormValue("description")
- if name == "" {
- JSONError(w, http.StatusBadRequest, "Feature name required", nil)
- return
- }
-
if err := h.store.CreateFeatureToggle(name, description, false); err != nil {
JSONError(w, http.StatusInternalServerError, "Failed to create feature", err)
return