func updateAttributesFromForm(res *wcg.Response, req *wcg.Request, e *event.Event) error { var err error if err = eventFormValidator.Eval(req.HttpRequest().PostForm); err != nil { return err } e.Title = req.Form("title") e.Link = req.Form("link") e.ImageLink = req.Form("image_link") e.YAKeyword = req.Form("ya_keyword") e.EventType = event.ParseEventType(req.Form("event_type")) return nil }
func updatePostHandler(res *wcg.Response, req *wcg.Request) { blog, _, err := fetchBlogForUpdate(res, req, false) if err != nil { return } post, err := fetchPostForUpdate(req, res, blog) if err != nil { return } post.Title = req.Form("title") post.Content = req.Form("content") post.IsDraft = req.Form("is_draft") == "true" post.IsNew = false post.PostDate, err = time.Parse(wcg.FormDateFormat, req.Form("post_date")) post.Tags = strings.Split(req.Form("tags"), ",") for i, v := range post.Tags { post.Tags[i] = strings.TrimSpace(v) } if err != nil { res.WriteHeader(400) res.WriteString("Invalid date format.") res.End() } driver := models.NewPostDriver(gae.NewContext(req), req.Logger) if AppConfig.GithubMarkdown { driver.HttpClient = gae.NewHttpClient(req) } err = driver.SavePost(post) if err != nil { if supports.IsValidationError(err) { res.WriteJsonWithStatus(400, nil, err) } else { res.RenderInternalError(err.Error()) } return } req.Logger.Info("A post is created at %s.", post.Id) res.WriteJsonWithStatus(200, nil, ok) }
func updateBlogHandler(res *wcg.Response, req *wcg.Request) { driver := models.NewBlogDriver(gae.NewContext(req), req.Logger) err := driver.UpdateBlog( req.Param("blog_id"), req.Form("title"), req.Form("description"), req.User.Id(), ) if err != nil { if supports.IsValidationError(err) { res.WriteJsonWithStatus(400, nil, err) } else if err == models.ErrBlogNotOwned { res.WriteJsonWithStatus(403, nil, no_permission) } else if err == models.ErrBlogNotFound { res.WriteJsonWithStatus(404, nil, not_found) } else { res.RenderInternalError(err.Error()) } return } res.WriteJsonWithStatus(200, nil, ok) }
func createBlogHandler(res *wcg.Response, req *wcg.Request) { driver := models.NewBlogDriver(gae.NewContext(req), req.Logger) blog, err := driver.CreateBlog( req.Form("path"), req.Form("title"), req.Form("description"), req.User.Id(), ) if err != nil { if err == models.ErrBlogAlreadyExists { res.WriteJsonWithStatus(409, nil, already_taken) } else if supports.IsValidationError(err) { res.WriteJsonWithStatus(400, nil, err) } else { res.RenderInternalError(err.Error()) } return } res.WriteJsonWithStatus(201, map[string]string{ "location": wcg.AbsoluteUrl(req, "/"+blog.Id), }, ok) }
func updateShowAttributes(req *wcg.Request, s *event.Show) *event.Show { s.OpenAt, _ = util.ParseDateTime(req.Form("open_at")) s.StartAt, _ = util.ParseDateTime(req.Form("start_at")) s.Latitude, _ = strconv.ParseFloat(req.Form("latitude"), 64) s.Longitude, _ = strconv.ParseFloat(req.Form("longitude"), 64) s.VenueId = req.Form("venue_id") s.VenueName = req.Form("venue_name") s.PiaLink = req.Form("pia_link") s.YAKeyword = req.Form("ya_keyword") return s }
func updateAttributesFromForm(res *wcg.Response, req *wcg.Request, p *blog.Post) error { var err error if err = postFormValidator.Eval(req.HttpRequest().PostForm); err != nil { return err } p.Title = req.Form("title") p.Content = req.Form("content") p.Tags = blog.ParseTagString(req.Form("tags")) p.IsDraft = req.Form("is_draft") == "true" p.IsHidden = req.Form("is_hidden") == "true" p.PublishAt, err = wcg.ParseDateTime(req.Form("publish_at")) return nil }