comments can be deleted

This commit is contained in:
Suraj 2016-02-16 22:23:15 +05:30
parent f800a32436
commit 87fd7d4ae2
2 changed files with 23 additions and 0 deletions

View File

@ -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)

View File

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