aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/app.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-05-01 15:07:45 -0400
committerGrant Ammons <gammons@gmail.com>2016-05-01 15:07:45 -0400
commit0905a863f50d9631e6c44488b952622e75d79785 (patch)
tree0634e9bd9e176660ad3d3260b24f08825aa85c67 /todolist/app.go
parentef9427646b9464d1f8c376f75741e737117a1a83 (diff)
Implement delete logic
Diffstat (limited to 'todolist/app.go')
-rw-r--r--todolist/app.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/todolist/app.go b/todolist/app.go
index e0f11d2..74fb8dc 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -3,6 +3,7 @@ package todolist
import (
"fmt"
"regexp"
+ "strconv"
)
type App struct {
@@ -24,6 +25,28 @@ func (a *App) AddTodo(input string) {
fmt.Println("Todo added.")
}
+func (a *App) DeleteTodo(input string) {
+ id := a.getId(input)
+ if id != -1 {
+ a.TodoStore.Delete(id)
+ a.TodoStore.Save()
+ fmt.Println("Todo deleted.")
+ } else {
+ fmt.Println("Could not find id.")
+ }
+}
+
+func (a *App) getId(input string) int {
+
+ re, _ := regexp.Compile("\\d+")
+ if re.MatchString(input) {
+ id, _ := strconv.Atoi(re.FindString(input))
+ return id
+ } else {
+ return -1
+ }
+}
+
func (a *App) ListTodos(input string) {
//filtered := NewFilter(a.TodoStore.Todos()).filter()
grouped := a.getGroups(input)