diff options
| -rw-r--r-- | todo.go | 2 | ||||
| -rw-r--r-- | todolist/app.go | 11 | ||||
| -rw-r--r-- | todolist/file_store.go | 7 | ||||
| -rw-r--r-- | todolist/file_store_test.go | 9 | ||||
| -rw-r--r-- | todolist/store.go | 1 | ||||
| -rw-r--r-- | todolist/todos.json | 2 |
6 files changed, 31 insertions, 1 deletions
@@ -32,5 +32,7 @@ func routeInput(command string, input string) { app.DeleteTodo(input) case command == "c" || command == "complete": app.CompleteTodo(input) + case command == "uc" || command == "uncomplete": + app.UncompleteTodo(input) } } diff --git a/todolist/app.go b/todolist/app.go index fec64d2..37961e0 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -47,6 +47,17 @@ func (a *App) CompleteTodo(input string) { } } +func (a *App) UncompleteTodo(input string) { + id := a.getId(input) + if id != -1 { + a.TodoStore.Uncomplete(id) + a.TodoStore.Save() + fmt.Println("Todo uncompleted.") + } else { + fmt.Println("Could not find id.") + } +} + func (a *App) ListTodos(input string) { //filtered := NewFilter(a.TodoStore.Todos()).filter() grouped := a.getGroups(input) diff --git a/todolist/file_store.go b/todolist/file_store.go index ce25b01..aa248d9 100644 --- a/todolist/file_store.go +++ b/todolist/file_store.go @@ -51,6 +51,13 @@ func (f *FileStore) Complete(id int) { f.Data = append(f.Data, *todo) } +func (f *FileStore) Uncomplete(id int) { + todo := f.FindById(id) + todo.Completed = false + f.Delete(id) + f.Data = append(f.Data, *todo) +} + func (f *FileStore) IndexOf(todoToFind *Todo) int { for i, todo := range f.Data { if todo.Id == todoToFind.Id { diff --git a/todolist/file_store_test.go b/todolist/file_store_test.go index 43b90d2..8817362 100644 --- a/todolist/file_store_test.go +++ b/todolist/file_store_test.go @@ -53,3 +53,12 @@ func TestComplete(t *testing.T) { store.Complete(1) assert.Equal(true, store.FindById(1).Completed) } + +func TestUncomplete(t *testing.T) { + assert := assert.New(t) + store := &FileStore{FileLocation: "todos.json"} + store.Load() + assert.Equal(true, store.FindById(2).Completed) + store.Uncomplete(2) + assert.Equal(false, store.FindById(2).Completed) +} diff --git a/todolist/store.go b/todolist/store.go index 066e3e3..2397d08 100644 --- a/todolist/store.go +++ b/todolist/store.go @@ -9,6 +9,7 @@ type Store interface { Delete(id int) Complete(id int) + Uncomplete(id int) IndexOf(t *Todo) int FindById(id int) *Todo diff --git a/todolist/todos.json b/todolist/todos.json index 2dbce64..5e44228 100644 --- a/todolist/todos.json +++ b/todolist/todos.json @@ -1 +1 @@ -[{"id":1,"subject":"this is the first subject","projects":["test1"],"contexts":["root"],"due":"2016-04-04","completed":false,"archived":true},{"id":2,"subject":" audit userify for 2FA","projects":["test1"],"contexts":["root","more"],"due":"","completed":false,"archived":false}]
\ No newline at end of file +[{"id":1,"subject":"this is the first subject","projects":["test1"],"contexts":["root"],"due":"2016-04-04","completed":false,"archived":true},{"id":2,"subject":" audit userify for 2FA","projects":["test1"],"contexts":["root","more"],"due":"","completed":true,"archived":false}]
\ No newline at end of file |
