Skip to content

Commit

Permalink
Merge pull request #83 from stuartskelton/Move_code_to_the_right_place
Browse files Browse the repository at this point in the history
Move code to the right place
  • Loading branch information
Grant Ammons authored Aug 5, 2017
2 parents c22022d + d59a098 commit e4fc41d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
16 changes: 16 additions & 0 deletions todolist/todo_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 13 additions & 13 deletions todolist/todo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit e4fc41d

Please sign in to comment.