aboutsummaryrefslogtreecommitdiffstats
path: root/todolist
diff options
context:
space:
mode:
authorStuart Skelton <stuarts@broadbean.com>2017-08-04 22:02:37 +0100
committerStuart Skelton <stuarts@broadbean.com>2017-08-04 22:02:37 +0100
commit05ad454f50422f0eab4228e819cbadbe9e6a918a (patch)
tree7a59c2cc79aa252956444f78dee945e89f461eaf /todolist
parentc22022d228b19f89aa84f8a7514b10c789ebea95 (diff)
Empower the todo_item to set its attributes correctly itself.
Diffstat (limited to 'todolist')
-rw-r--r--todolist/todo_item.go16
-rw-r--r--todolist/todo_list.go9
2 files changed, 20 insertions, 5 deletions
diff --git a/todolist/todo_item.go b/todolist/todo_item.go
index eecb409..0c30707 100644
--- a/todolist/todo_item.go
+++ b/todolist/todo_item.go
@@ -45,6 +45,22 @@ func (t *Todo) Uncomplete() {
t.CompletedDate = ""
}
+func (t *Todo) Archive() {
+ t.Archived = true
+}
+
+func (t *Todo) Unarchive() {
+ t.Archived = false
+}
+
+func (t *Todo) Prioritize() {
+ t.IsPriority = true
+}
+
+func (t *Todo) Unprioritize() {
+ t.IsPriority = false
+}
+
func (t Todo) CompletedDateToDate() string {
parsedTime, _ := time.Parse(ISO8601_TIMESTAMP_FORMAT, t.CompletedDate)
return parsedTime.Format("2006-01-02")
diff --git a/todolist/todo_list.go b/todolist/todo_list.go
index 6bab407..a1e9f1c 100644
--- a/todolist/todo_list.go
+++ b/todolist/todo_list.go
@@ -42,14 +42,14 @@ func (t *TodoList) Uncomplete(id int) {
func (t *TodoList) Archive(id int) {
todo := t.FindById(id)
- todo.Archived = true
+ todo.Archive()
t.Delete(id)
t.Data = append(t.Data, todo)
}
func (t *TodoList) Unarchive(id int) {
todo := t.FindById(id)
- todo.Archived = false
+ todo.Unarchive()
t.Delete(id)
t.Data = append(t.Data, todo)
}
@@ -62,17 +62,16 @@ func (t *TodoList) IndexOf(todoToFind *Todo) int {
}
return -1
}
-
func (t *TodoList) Prioritize(id int) {
todo := t.FindById(id)
- todo.IsPriority = true
+ todo.Prioritize()
t.Delete(id)
t.Data = append(t.Data, todo)
}
func (t *TodoList) Unprioritize(id int) {
todo := t.FindById(id)
- todo.IsPriority = false
+ todo.Unprioritize()
t.Delete(id)
t.Data = append(t.Data, todo)
}