// Edit an account for a given shop. func EditAccount(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop, token string) string { var c cart.Customer defer req.Body.Close() data, err := ioutil.ReadAll(req.Body) if err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } if err = json.Unmarshal(data, &c); err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } c.ShopId = shop.Id c.Id, err = cart.IdentifierFromToken(token) if err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } if err = c.Update(); err != nil { apierror.GenerateError(err.Error(), err, w, req) return "" } return encoding.Must(enc.Encode(c)) }
// 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)) }