From 87fd7d4ae21e0808bf493a14fde814dad5f8fddf Mon Sep 17 00:00:00 2001 From: Suraj Date: Tue, 16 Feb 2016 22:23:15 +0530 Subject: [PATCH] comments can be deleted --- main.go | 1 + views/deleteViews.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/main.go b/main.go index a95bd5c..c4442bf 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ func main() { http.HandleFunc("/", views.ShowAllTasksFunc) http.HandleFunc("/add-category/", views.AddCategoryFunc) http.HandleFunc("/add-comment/", views.AddCommentFunc) + http.HandleFunc("/del-comment/", views.DeleteCommentFunc) http.HandleFunc("/del-category/", views.DeleteCategoryFunc) http.HandleFunc("/upd-category/", views.UpdateCategoryFunc) http.HandleFunc("/category/", views.ShowCategoryFunc) diff --git a/views/deleteViews.go b/views/deleteViews.go index 2b6ca51..5ace61f 100644 --- a/views/deleteViews.go +++ b/views/deleteViews.go @@ -130,3 +130,25 @@ func DeleteCategoryFunc(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", http.StatusFound) } } + +//DeleteCommentFunc will delete any category +func DeleteCommentFunc(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" { + id := r.URL.Path[len("/del-comment/"):] + commentID, err := strconv.Atoi(id) + if err != nil { + http.Redirect(w, r, "/", http.StatusBadRequest) + return + } + + err = db.DeleteCommentByID(commentID) + + if err != nil { + message = "comment not deleted" + } else { + message = "comment deleted" + } + + http.Redirect(w, r, "/", http.StatusFound) + } +}