Example #1
0
func Lookup(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var v products.NoSqlVehicle
	var collection string //e.g. interior/exterior

	//Get collection
	collection = r.FormValue("collection")
	delete(r.Form, "collection")

	// Get vehicle year
	v.Year = r.FormValue("year")
	delete(r.Form, "year")

	// Get vehicle make
	v.Make = r.FormValue("make")
	delete(r.Form, "make")

	// Get vehicle model
	v.Model = r.FormValue("model")
	delete(r.Form, "model")

	// Get vehicle submodel
	v.Style = r.FormValue("style")
	delete(r.Form, "style")

	l, err := products.FindVehicles(v, collection, dtx)
	if err != nil {
		apierror.GenerateError("Trouble finding vehicles.", err, w, r)
		return ""
	}

	return encoding.Must(enc.Encode(l))
}
Example #2
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))
}
Example #3
0
//Hack version that slowly traverses all the collection and aggregates results
func AllCollectionsLookup(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var v products.NoSqlVehicle

	//Get all collections
	cols, err := products.GetAriesVehicleCollections()
	if err != nil {
		apierror.GenerateError(err.Error(), err, w, r)
		return ""
	}

	// Get vehicle year
	v.Year = r.FormValue("year")
	delete(r.Form, "year")

	// Get vehicle make
	v.Make = r.FormValue("make")
	delete(r.Form, "make")

	// Get vehicle model
	v.Model = r.FormValue("model")
	delete(r.Form, "model")

	// Get vehicle submodel
	v.Style = r.FormValue("style")
	delete(r.Form, "style")

	var collectionVehicleArray []products.NoSqlLookup

	for _, col := range cols {
		noSqlLookup, err := products.FindVehiclesWithParts(v, col, dtx)
		if err != nil {
			apierror.GenerateError("Trouble finding vehicles.", err, w, r)
			return ""
		}
		collectionVehicleArray = append(collectionVehicleArray, noSqlLookup)
	}
	l := makeLookupFrommanyLookups(collectionVehicleArray)

	return encoding.Must(enc.Encode(l))
}
Example #4
0
//return parts for a vehicle(incl style) within a specific category
func AllCollectionsLookupCategory(w http.ResponseWriter, r *http.Request, enc encoding.Encoder, dtx *apicontext.DataContext) string {
	var v products.NoSqlVehicle
	noSqlLookup := make(map[string]products.NoSqlLookup)
	var err error

	// Get vehicle year
	v.Year = r.FormValue("year")
	delete(r.Form, "year")

	// Get vehicle make
	v.Make = r.FormValue("make")
	delete(r.Form, "make")

	// Get vehicle model
	v.Model = r.FormValue("model")
	delete(r.Form, "model")

	// // Get vehicle submodel
	v.Style = r.FormValue("style")
	delete(r.Form, "style")

	collection := r.FormValue("collection")
	if collection == "" {
		noSqlLookup, err = products.FindVehiclesFromAllCategories(v, dtx)

	} else {
		noSqlLookup, err = products.FindPartsFromOneCategory(v, collection, dtx)
	}
	if err != nil {
		apierror.GenerateError("Trouble finding vehicles.", err, w, r)
		return ""
	}

	return encoding.Must(enc.Encode(noSqlLookup))

	return ""
}