func (c *Context) DoCreateFactHandler(rw web.ResponseWriter, req *web.Request) { req.ParseForm() var f fact.Fact if err := decoder.Decode(&f, req.PostForm); err != nil { c.SetErrorMessage(rw, req, "Decoding error: "+err.Error()) http.Redirect(rw, req.Request, CreateFactUrl.Make(), http.StatusSeeOther) return } f.AccountId = c.Account.Id if err := fact.CreateFact(c.Storage, &f); err != nil { c.SetFailedRequestObject(rw, req, f) c.SetErrorMessage(rw, req, err.Error()) http.Redirect(rw, req.Request, CreateFactUrl.Make(), http.StatusSeeOther) return } c.SetNotificationMessage(rw, req, "Fact submitted successfully!") http.Redirect(rw, req.Request, ViewFactUrl.Make("factId", strconv.FormatInt(f.Id, 10)), http.StatusFound) }
func (s *DatabaseStorage) ModerateFact(f *fact.Fact, enable bool) error { f.AwaitModeration = enable return s.dbGorm.Save(f).Error }
func (s *DatabaseStorage) CreateFact(f *fact.Fact) error { f.AwaitModeration = true return s.dbGorm.Create(f).Error }