summaryrefslogtreecommitdiff
path: root/internal/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handlers')
-rw-r--r--internal/handlers/chains_test.go8
-rw-r--r--internal/handlers/chains_timeline_test.go6
-rw-r--r--internal/handlers/widget.go15
3 files changed, 21 insertions, 8 deletions
diff --git a/internal/handlers/chains_test.go b/internal/handlers/chains_test.go
index 0ebcc7a..bf657d1 100644
--- a/internal/handlers/chains_test.go
+++ b/internal/handlers/chains_test.go
@@ -9,6 +9,8 @@ import (
"testing"
"github.com/go-chi/chi/v5"
+
+ "task-dashboard/internal/models"
)
func withURLParam(req *http.Request, key, value string) *http.Request {
@@ -22,7 +24,7 @@ func TestHandleWidgetChainsCreate_CreatesChain(t *testing.T) {
defer cleanup()
h := &Handler{store: db}
- body := `{"name":"Ham Radio Track","tasks":["Study Technician","Pass exam"]}`
+ body := `{"name":"Ham Radio Track","tasks":[{"content":"Study Technician"},{"content":"Pass exam","description":"Pick a date","priority":3}]}`
req := httptest.NewRequest("POST", "/api/widget/chains", strings.NewReader(body))
w := httptest.NewRecorder()
h.HandleWidgetChainsCreate(w, req)
@@ -67,7 +69,7 @@ func TestHandleWidgetChainGet_ReturnsChainAndTasks(t *testing.T) {
defer cleanup()
h := &Handler{store: db}
- chain, err := h.store.CreateChain("Track", []string{"Step 1", "Step 2"})
+ chain, err := h.store.CreateChain("Track", []models.ChainTaskInput{{Content: "Step 1"}, {Content: "Step 2"}})
if err != nil {
t.Fatal(err)
}
@@ -107,7 +109,7 @@ func TestHandleWidgetChainsPauseResumeAbandon(t *testing.T) {
defer cleanup()
h := &Handler{store: db}
- chain, err := h.store.CreateChain("Track", []string{"Step 1", "Step 2"})
+ chain, err := h.store.CreateChain("Track", []models.ChainTaskInput{{Content: "Step 1"}, {Content: "Step 2"}})
if err != nil {
t.Fatal(err)
}
diff --git a/internal/handlers/chains_timeline_test.go b/internal/handlers/chains_timeline_test.go
index 76ceb68..e9c8a3a 100644
--- a/internal/handlers/chains_timeline_test.go
+++ b/internal/handlers/chains_timeline_test.go
@@ -4,13 +4,17 @@ import (
"context"
"testing"
"time"
+
+ "task-dashboard/internal/models"
)
func TestBuildTimeline_PopulatesChainBadgeForUnlockedTask(t *testing.T) {
s, cleanup := setupTestDB(t)
defer cleanup()
- chain, err := s.CreateChain("Ham Radio Track", []string{"Study Technician", "Pass exam", "Study General"})
+ chain, err := s.CreateChain("Ham Radio Track", []models.ChainTaskInput{
+ {Content: "Study Technician"}, {Content: "Pass exam"}, {Content: "Study General"},
+ })
if err != nil {
t.Fatal(err)
}
diff --git a/internal/handlers/widget.go b/internal/handlers/widget.go
index de2e856..a7f7b66 100644
--- a/internal/handlers/widget.go
+++ b/internal/handlers/widget.go
@@ -963,8 +963,8 @@ func (h *Handler) HandleWidgetLabelsBudgetTracked(w http.ResponseWriter, r *http
}
type chainCreateRequest struct {
- Name string `json:"name"`
- Tasks []string `json:"tasks"`
+ Name string `json:"name"`
+ Tasks []models.ChainTaskInput `json:"tasks"`
}
type chainCreateResponse struct {
@@ -972,8 +972,9 @@ type chainCreateResponse struct {
}
// HandleWidgetChainsCreate creates a linear task chain: a backing project
-// plus one native_tasks row per title in req.Tasks, position 0 unlocked and
-// due now, the rest locked with no due date.
+// plus one native_tasks row per entry in req.Tasks (content required;
+// description and priority optional, priority defaulting to 1), position 0
+// unlocked and due now, the rest locked with no due date.
func (h *Handler) HandleWidgetChainsCreate(w http.ResponseWriter, r *http.Request) {
var req chainCreateRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -984,6 +985,12 @@ func (h *Handler) HandleWidgetChainsCreate(w http.ResponseWriter, r *http.Reques
http.Error(w, "name and at least one task are required", http.StatusBadRequest)
return
}
+ for _, t := range req.Tasks {
+ if strings.TrimSpace(t.Content) == "" {
+ http.Error(w, "every task requires non-empty content", http.StatusBadRequest)
+ return
+ }
+ }
chain, err := h.store.CreateChain(req.Name, req.Tasks)
if err != nil {
http.Error(w, "failed to create chain", http.StatusInternalServerError)