diff --git a/db/db.go b/db/db.go index afa710e..1e6f06c 100644 --- a/db/db.go +++ b/db/db.go @@ -168,6 +168,26 @@ func RestoreTask(id int) error { return err } +//RestoreTaskFromComplete is used to restore tasks from the Trash +func RestoreTaskFromComplete(id int) error { + restoreSQL, err := database.Prepare("update task set is_deleted='N',finish_date=null,last_modified_at=datetime() where id=?") + if err != nil { + fmt.Println(err) + } + tx, err := database.Begin() + if err != nil { + fmt.Println(err) + } + _, err = tx.Stmt(restoreSQL).Exec(id) + if err != nil { + fmt.Println("doing rollback") + tx.Rollback() + } else { + tx.Commit() + } + return err +} + //DeleteTask is used to delete the task from the database func DeleteTask(id int) error { deleteSQL, err := database.Prepare("delete from task where id = ?") diff --git a/main.go b/main.go index 7ff258f..9499db1 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ func main() { http.HandleFunc("/edit/", views.EditTaskFunc) http.HandleFunc("/completed/", views.ShowCompleteTasksFunc) http.HandleFunc("/restore/", views.RestoreTaskFunc) + http.HandleFunc("/incomplete/", views.RestoreFromCompleteFunc) http.HandleFunc("/add/", views.AddTaskFunc) http.HandleFunc("/update/", views.UpdateTaskFunc) http.HandleFunc("/search/", views.SearchTaskFunc) diff --git a/public/templates/completed.html b/public/templates/completed.html index f29538a..41baea6 100644 --- a/public/templates/completed.html +++ b/public/templates/completed.html @@ -8,11 +8,15 @@
{{.Content}}