From 0905a863f50d9631e6c44488b952622e75d79785 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Sun, 1 May 2016 15:07:45 -0400 Subject: Implement delete logic --- todolist/app.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'todolist/app.go') 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) -- cgit v1.3