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) + } +}