Exemple #1
0
func ProductCreateHandler(w http.ResponseWriter, r *http.Request) {
	productController := controller.Product{}

	//verify user is admin
	adminAuth := auth.Auth{}
	status := adminAuth.VerifyAdmin(r)

	if status == true {
		err := productController.CreateProduct(r)

		if err != nil {
			log.Println(err)
		} else {
			fmt.Fprint(w, true)
		}
	}
}
Exemple #2
0
func ProductGetHandler(w http.ResponseWriter, r *http.Request) {
	//product id
	vars := mux.Vars(r)
	strId := vars["id"]

	id, err := strconv.ParseInt(strId, 10, 64)

	if err != nil {
		log.Println(err)
	}

	productController := controller.Product{}
	product, err := productController.GetProduct(r, id)

	if err != nil {
		log.Println(err)
	} else {
		jsonRes, _ := json.Marshal(product)
		fmt.Fprint(w, string(jsonRes))
	}
}