// Get an account for a given shop func GetAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop, token string) string { cust := cart.Customer{ ShopId: shop.Id, } var err error cust.Id, err = cart.IdentifierFromToken(token) if err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } if err = cust.Get(); err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } return encoding.Must(enc.Encode(cust)) }
func UpdateBlog(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params, dtx *apicontext.DataContext) string { var b blog_model.Blog var err error idStr := r.FormValue("id") if idStr != "" { b.ID, err = strconv.Atoi(idStr) if err != nil { apierror.GenerateError("Trouble getting blog ID", err, rw, r) } } else { b.ID, err = strconv.Atoi(params["id"]) if err != nil { apierror.GenerateError("Trouble getting blog ID", err, rw, r) } } b.Get(dtx) var tempBC []blog_model.BlogCategory title := r.FormValue("title") slug := r.FormValue("slug") text := r.FormValue("text") publishedDate := r.FormValue("publishedDate") userID := r.FormValue("userID") metaTitle := r.FormValue("metaTitle") metaDescription := r.FormValue("metaDescription") keywords := r.FormValue("keywords") active := r.FormValue("active") categoryIDs := r.Form["categoryID"] for _, v := range categoryIDs { var bc blog_model.BlogCategory bc.Category.ID, err = strconv.Atoi(v) tempBC = append(tempBC, bc) } if err != nil { apierror.GenerateError("Trouble getting blog", err, rw, r) return err.Error() } if title != "" { b.Title = title } if slug != "" { b.Slug = slug } if text != "" { b.Text = text } if publishedDate != "" { b.PublishedDate, err = time.Parse(timeFormat, publishedDate) } if userID != "" { b.UserID, err = strconv.Atoi(userID) } if metaTitle != "" { b.MetaTitle = metaTitle } if metaDescription != "" { b.MetaDescription = metaDescription } if keywords != "" { b.Keywords = keywords } if active != "" { b.Active, err = strconv.ParseBool(active) } if categoryIDs != nil { b.BlogCategories = tempBC } err = b.Update(dtx) if err != nil { apierror.GenerateError("Trouble updating blog", err, rw, r) } return encoding.Must(enc.Encode(b)) }