Esempio n. 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))
}
Esempio n. 2
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))
}
Esempio n. 3
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 ""
}