Exemplo n.º 1
0
func (pc *partController) GetSearch(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	makeId, _ := strconv.Atoi(vars["makeId"])
	modelId, _ := strconv.Atoi(vars["modelId"])
	yearId, _ := strconv.Atoi(vars["yearId"])
	engineId, _ := strconv.Atoi(vars["engineId"])
	categories, err := model.GetPartCategories()

	if err != nil {
		log.Println(err)
		w.WriteHeader(500)
	} else {
		employeeNumber, _ := strconv.Atoi(vars["employeeNumber"])
		employee, _ := model.GetEmployee(employeeNumber)
		autoMake, _ := model.GetMake(makeId)
		autoModel, _ := model.GetModel(modelId)
		autoYear, _ := model.GetYear(yearId)
		autoEngine, _ := model.GetEngine(engineId)

		categoriesJSON, _ := json.Marshal(categories)

		vmodel := vm.SearchResult{Base: vm.Base{Employee: employee},
			Make:           autoMake,
			Model:          autoModel,
			Year:           autoYear,
			Engine:         autoEngine,
			CategoriesJSON: string(categoriesJSON),
		}

		pc.searchResultTemplate.Execute(w, vmodel)
	}
}
Exemplo n.º 2
0
func (pc *partController) GetEngine(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)

	makeId, _ := strconv.Atoi(vars["makeId"])

	modelId, _ := strconv.Atoi(vars["modelId"])

	yearId, _ := strconv.Atoi(vars["yearId"])

	engines, err := model.SearchForEngines(modelId, yearId)
	if err != nil {
		log.Println(err)
		w.WriteHeader(500)
	} else {
		employeeNumber, _ := strconv.Atoi(vars["employeeNumber"])
		if err != nil {
			log.Println(err)
			w.WriteHeader(500)
		} else {
			employee, _ := model.GetEmployee(employeeNumber)
			autoModel, _ := model.GetModel(modelId)
			autoMake, _ := model.GetMake(makeId)
			autoYear, _ := model.GetYear(yearId)

			vmodel := vm.PartEngine{Base: vm.Base{Employee: employee},
				Make:    autoMake,
				Model:   autoModel,
				Year:    autoYear,
				Engines: engines,
			}
			pc.autoEngineTemplate.Execute(w, vmodel)
		}
	}
}