diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-07-15 18:17:47 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-07-16 02:54:17 +0000 |
| commit | d5750f2268be5164159dcd81901a10b0496525b7 (patch) | |
| tree | 05937fd9cf44294e4fd17496077b7ae81c342389 /internal/store/labels.go | |
| parent | a2afca944b28d0253c02cf72aa210df3ed4b3de5 (diff) | |
feat(tasks): add label color CRUD store methods
Diffstat (limited to 'internal/store/labels.go')
| -rw-r--r-- | internal/store/labels.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/store/labels.go b/internal/store/labels.go new file mode 100644 index 0000000..3c5f5eb --- /dev/null +++ b/internal/store/labels.go @@ -0,0 +1,46 @@ +package store + +import ( + "encoding/json" + + "task-dashboard/internal/models" +) + +// SetTaskLabels replaces a task's label set entirely (not an add/remove +// single-label API), matching UpdateNativeTask's replace-whole-value style. +// Returns ErrNativeTaskNotFound if id doesn't match any row. +func (s *Store) SetTaskLabels(id string, labels []string) error { + labelsJSON, _ := json.Marshal(labels) + result, err := s.db.Exec(` + UPDATE native_tasks SET labels = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? + `, string(labelsJSON), id) + if err != nil { + return err + } + return checkRowsAffected(result) +} + +// GetLabelColors returns every label that has been assigned a color. +func (s *Store) GetLabelColors() ([]models.LabelColor, error) { + rows, err := s.db.Query(`SELECT name, color FROM labels ORDER BY name ASC`) + if err != nil { + return nil, err + } + defer func() { _ = rows.Close() }() + + var colors []models.LabelColor + for rows.Next() { + var c models.LabelColor + if err := rows.Scan(&c.Name, &c.Color); err != nil { + return nil, err + } + colors = append(colors, c) + } + return colors, rows.Err() +} + +// SetLabelColor assigns (or reassigns) a label's display color. +func (s *Store) SetLabelColor(name, color string) error { + _, err := s.db.Exec(`INSERT OR REPLACE INTO labels (name, color) VALUES (?, ?)`, name, color) + return err +} |
