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