func GetThread(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string { var err error var thread forum.Thread if thread.ID, err = strconv.Atoi(params["id"]); err != nil { apierror.GenerateError("Trouble getting forum thread ID", err, rw, req) } if err := thread.Get(dtx); err != nil { apierror.GenerateError("Trouble getting forum thread", err, rw, req) } return encoding.Must(enc.Encode(thread)) }
func UpdatePost(rw http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, dtx *apicontext.DataContext) string { var err error var post forum.Post if post.ID, err = strconv.Atoi(params["id"]); err != nil { apierror.GenerateError("Trouble getting post ID", err, rw, req) } if err = post.Get(dtx); err != nil { apierror.GenerateError("Trouble getting post", err, rw, req) } if req.FormValue("parentID") != "" { var parentPost forum.Post if parentPost.ID, err = strconv.Atoi(req.FormValue("parentID")); err != nil { apierror.GenerateError("Trouble updating post -- parent post ID is invalid", err, rw, req) } if err = parentPost.Get(dtx); err != nil { apierror.GenerateError("Trouble updating post -- failed to get parent post", err, rw, req) } post.ParentID = parentPost.ID } if req.FormValue("threadID") != "" { var thread forum.Thread if thread.ID, err = strconv.Atoi(req.FormValue("threadID")); err != nil { apierror.GenerateError("Trouble updating post -- thread ID is invalid", err, rw, req) } if err = thread.Get(dtx); err != nil { apierror.GenerateError("Trouble updating post -- thread was not found", err, rw, req) } post.ThreadID = thread.ID } if req.FormValue("approved") != "" { if post.Approved, err = strconv.ParseBool(req.FormValue("approved")); err != nil { apierror.GenerateError("Trouble updating post -- boolean approved parameter is invalid", err, rw, req) } } if req.FormValue("active") != "" { if post.Approved, err = strconv.ParseBool(req.FormValue("active")); err != nil { apierror.GenerateError("Trouble updating post -- boolean active parameter is invalid", err, rw, req) } } if req.FormValue("notify") != "" { if post.Notify, err = strconv.ParseBool(req.FormValue("notify")); err != nil { apierror.GenerateError("Trouble updating post -- boolean notify parameter is invalid", err, rw, req) } } if req.FormValue("sticky") != "" { if post.Sticky, err = strconv.ParseBool(req.FormValue("sticky")); err != nil { apierror.GenerateError("Trouble updating post -- boolean sticky parameter is invalid", err, rw, req) } } if req.FormValue("flag") != "" { if post.Flag, err = strconv.ParseBool(req.FormValue("flag")); err != nil { apierror.GenerateError("Trouble updating post -- boolean flag parameter is invalid", err, rw, req) } } if req.FormValue("title") != "" { post.Title = req.FormValue("title") } if req.FormValue("post") != "" { post.Post = req.FormValue("post") } if req.FormValue("name") != "" { post.Name = req.FormValue("name") } if req.FormValue("email") != "" { post.Email = req.FormValue("email") } if req.FormValue("company") != "" { post.Company = req.FormValue("company") } //post.IPAddress = "" if err = post.Update(); err != nil { apierror.GenerateError("Trouble updating post", err, rw, req) } return encoding.Must(enc.Encode(post)) }