aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-05-02 07:25:51 -0400
committerGrant Ammons <gammons@gmail.com>2016-05-02 07:25:51 -0400
commit34c89ec2ca4b458adb94534c4fae44c921181f59 (patch)
treeed3b9e7ab295543938ac4ee2fcadbe915749dd98
parent54e9313ad14269f57a13b32aac59aea17f86d151 (diff)
Uncomplete todo
-rw-r--r--todo.go2
-rw-r--r--todolist/app.go11
-rw-r--r--todolist/file_store.go7
-rw-r--r--todolist/file_store_test.go9
-rw-r--r--todolist/store.go1
-rw-r--r--todolist/todos.json2
6 files changed, 31 insertions, 1 deletions
diff --git a/todo.go b/todo.go
index 813b1fc..a945aba 100644
--- a/todo.go
+++ b/todo.go
@@ -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