func reqSave(w http.ResponseWriter, r *http.Request, params martini.Params) { if !checkLogin(w, r) { libs.OutJson(w, r, 1, "auth error!") return } r.ParseForm() docId, _ := strconv.ParseInt(params["docId"], 10, 64) catId, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64) md := new(model.Md) md.CategoryId = int(catId) md.Title = r.PostForm.Get("title") md.Content = r.PostForm.Get("content") md.Draft = r.PostForm.Get("draft") i, err := libs.DB.Id(docId).Update(md) libs.DB.Where("md_id=?", params["docId"]).Delete(new(model.MdTag)) for _, v := range r.PostForm["tags[]"] { tid, _ := strconv.ParseInt(v, 10, 64) md_tag := model.MdTag{ MdId: int(docId), TagId: int(tid), } libs.DB.Insert(md_tag) } if err != nil { libs.OutJson(w, r, 1, err.Error()) return } libs.OutJson(w, r, 0, i) }
func reqDelete(w http.ResponseWriter, r *http.Request, params martini.Params) { if !checkLogin(w, r) { libs.OutJson(w, r, 1, "auth error!") return } r.ParseForm() docId, _ := strconv.ParseInt(params["docId"], 10, 64) var md model.Md if i, err := libs.DB.Id(docId).Delete(&md); i == 0 { http.Error(w, err.Error(), 404) return } http.Redirect(w, r, "/", http.StatusFound) }