Ejemplo n.º 1
0
// Delete a customer for a given shop.
// Note: Can't delete if the customer has existing orders.
func DeleteCustomer(w http.ResponseWriter, req *http.Request, params martini.Params, enc encoding.Encoder, shop *cart.Shop) string {

	var c cart.Customer
	customerId := params["id"]

	if !bson.IsObjectIdHex(customerId) {
		apierror.GenerateError("invalid customer reference", nil, w, req)
		return ""
	}
	c.Id = bson.ObjectIdHex(customerId)
	c.ShopId = shop.Id

	if err := c.Delete(); err != nil {
		apierror.GenerateError(err.Error(), err, w, req)
		return ""
	}

	return ""
}