示例#1
0
文件: api.go 项目: pascalj/disgo
// ApproveComment allows admins to approve a comment by id.
func ApproveComment(w http.ResponseWriter, req *http.Request, app *App) {
	vars := mux.Vars(req)
	id, err := strconv.Atoi(vars["id"])
	if err != nil {
		w.WriteHeader(422)
		return
	}
	comment := models.GetComment(app.Db, id)
	if comment == nil {
		w.WriteHeader(404)
	} else {
		comment.Approved = true
		comment.Save(app.Db)
		http.Redirect(w, req, "/admin", 303)
	}
}
示例#2
0
文件: api.go 项目: pascalj/disgo
// DestroyComment deletes a comment from the database by id.
func DestroyComment(w http.ResponseWriter, req *http.Request, app *App) {
	vars := mux.Vars(req)
	id, err := strconv.Atoi(vars["id"])
	if err != nil {
		w.WriteHeader(422)
		return
	}
	comment := models.GetComment(app.Db, id)
	if comment == nil {
		w.WriteHeader(404)
	} else {
		err := comment.Delete(app.Db)
		if err != nil {
			w.WriteHeader(500)
		} else {
			http.Redirect(w, req, "/admin", 303)
		}
	}
}