forked from OrgGo/Tasks
comments can be deleted
This commit is contained in:
parent
f800a32436
commit
87fd7d4ae2
1
main.go
1
main.go
|
@ -18,6 +18,7 @@ func main() {
|
||||||
http.HandleFunc("/", views.ShowAllTasksFunc)
|
http.HandleFunc("/", views.ShowAllTasksFunc)
|
||||||
http.HandleFunc("/add-category/", views.AddCategoryFunc)
|
http.HandleFunc("/add-category/", views.AddCategoryFunc)
|
||||||
http.HandleFunc("/add-comment/", views.AddCommentFunc)
|
http.HandleFunc("/add-comment/", views.AddCommentFunc)
|
||||||
|
http.HandleFunc("/del-comment/", views.DeleteCommentFunc)
|
||||||
http.HandleFunc("/del-category/", views.DeleteCategoryFunc)
|
http.HandleFunc("/del-category/", views.DeleteCategoryFunc)
|
||||||
http.HandleFunc("/upd-category/", views.UpdateCategoryFunc)
|
http.HandleFunc("/upd-category/", views.UpdateCategoryFunc)
|
||||||
http.HandleFunc("/category/", views.ShowCategoryFunc)
|
http.HandleFunc("/category/", views.ShowCategoryFunc)
|
||||||
|
|
|
@ -130,3 +130,25 @@ func DeleteCategoryFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue