summaryrefslogtreecommitdiff
path: root/internal/handlers/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers/handlers.go')
-rw-r--r--internal/handlers/handlers.go40
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)