aboutsummaryrefslogtreecommitdiffstats
path: root/todolist
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-08-05 07:49:37 -0400
committerGitHub <noreply@github.com>2017-08-05 07:49:37 -0400
commite4fc41d2ca95e5fad0eeb9bc40996e2687f78d06 (patch)
tree4a290e9787bb8379a37183b63f4a53a8cdb8c563 /todolist
parentc22022d228b19f89aa84f8a7514b10c789ebea95 (diff)
parentd59a0986f51e8a09c6c15446f7141acf86d27d41 (diff)
Merge pull request #83 from stuartskelton/Move_code_to_the_right_place0.7
Move code to the right place
Diffstat (limited to 'todolist')
-rw-r--r--todolist/todo_item.go16
-rw-r--r--todolist/todo_list.go26
2 files changed, 29 insertions, 13 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..4623a22 100644
--- a/todolist/todo_list.go
+++ b/todolist/todo_list.go
@@ -42,41 +42,41 @@ 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)
}
-func (t *TodoList) IndexOf(todoToFind *Todo) int {
- for i, todo := range t.Data {
- if todo.Id == todoToFind.Id {
- return i
- }
- }
- 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)
}
+func (t *TodoList) IndexOf(todoToFind *Todo) int {
+ for i, todo := range t.Data {
+ if todo.Id == todoToFind.Id {
+ return i
+ }
+ }
+ return -1
+}
+
type ByDate []*Todo
func (a ByDate) Len() int { return len(a) }