Пример #1
0
func GetSales(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params) string {
	var err error
	var ps customer.Prices
	var c customer.Customer

	id := r.FormValue("id")
	if id == "" {
		id = params["id"]
	}

	if c.Id, err = strconv.Atoi(id); err != nil {
		apierror.GenerateError("Trouble getting customer ID", err, rw, r)
		return ""
	}

	start := r.FormValue("start")
	end := r.FormValue("end")

	startDate, err := time.Parse(inputTimeFormat, start)
	if err != nil {
		apierror.GenerateError("Trouble getting sales start date", err, rw, r)
		return ""
	}

	endDate, err := time.Parse(inputTimeFormat, end)
	if err != nil {
		apierror.GenerateError("Trouble getting sales end date", err, rw, r)
		return ""
	}

	ps, err = c.GetPricesBySaleRange(startDate, endDate)
	if err != nil {
		apierror.GenerateError("Trouble getting prices by sales range", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(ps))
}