示例#1
0
func CreateApplication(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext, params martini.Params) string {
	var app products.NoSqlVehicle
	collection := params["collection"]
	if collection == "" {
		apierror.GenerateError("No Collection in URL", nil, w, r)
		return ""
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		apierror.GenerateError("Error reading request body", nil, w, r)
		return ""
	}

	if err = json.Unmarshal(body, &app); err != nil {
		apierror.GenerateError("Error decoding vehicle application", nil, w, r)
		return ""
	}

	if err = app.Create(collection); err != nil {
		apierror.GenerateError("Error updating vehicle", nil, w, r)
		return ""
	}
	return encoding.Must(enc.Encode(app))
}