当前位置: 首页>>代码示例>>Golang>>正文


Golang models.Product类代码示例

本文整理汇总了Golang中models.Product的典型用法代码示例。如果您正苦于以下问题:Golang Product类的具体用法?Golang Product怎么用?Golang Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Product类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: get

func (this *profileController) get(w http.ResponseWriter, req *http.Request) {
	vm := viewmodels.GetProfile()

	responseWriter := util.GetResponseWriter(w, req)

	ck, err := req.Cookie("goSessionId")

	if err == nil {
		vm.LoggedIn = true

		userId, _ := strconv.Atoi(ck.Value)
		modelMember, _ := models.GetMemberById(userId)
		vm.Member = converter.ConvertMemberlToViewModel(modelMember)

		if req.Method == "GET" {
			var listOfProductIds []int
			listOfProductIds, _ = models.GetMembersOrder(userId)

			var listOfProducts []viewmodels.Product
			for _, val := range listOfProductIds {
				pr, _ := models.GetProduct(val)
				listOfProducts = append(listOfProducts, converter.ConvertProductsToViewModel(pr))
			}

			vm.Products = listOfProducts
			vm.LoggedIn = true

		} else {
			remButton := req.FormValue("remove")
			remId, _ := strconv.Atoi(remButton)

			if remButton == "" {
				productName := req.FormValue("name")
				productType := req.FormValue("type")
				productDescription := req.FormValue("description")
				productPrice := req.FormValue("price")
				productImgUrl := req.FormValue("imageurl")

				_, fileErr := models.GetProductByName(productName)

				if fileErr != nil {
					inputProduct := models.Product{}
					inputProduct.SetName(productName)
					inputProduct.SetDescription(productDescription)
					inputProduct.SetImageUrl(productImgUrl)

					typ, _ := strconv.Atoi(productType)
					inputProduct.SetTyp(typ)

					price64, _ := strconv.ParseFloat(productPrice, 2)
					price := float32(price64)
					inputProduct.SetPrice(price)

					insertErr := models.InsertProduct(inputProduct)

					if insertErr == nil {
						http.Redirect(w, req, "/profile", http.StatusFound)
					} else {
						log.Fatal(insertErr.Error())
					}

				} else {
					http.Redirect(w, req, "/home", http.StatusFound)
				}
			} else {
				deleteErr := models.RemoveOrder(userId, remId)

				if deleteErr == nil {
					http.Redirect(w, req, "/profile", http.StatusFound)
				}
			}
		}

	} else {
		http.Redirect(w, req, "/login", http.StatusFound)
	}

	w.Header().Add("Content-Type", "text/html")
	this.template.Execute(responseWriter, vm)
	defer responseWriter.Close()
}
开发者ID:Ikanant,项目名称:GolangWebApp,代码行数:81,代码来源:profile.go

示例2: ConvertProductsToViewModel

func ConvertProductsToViewModel(product models.Product) viewmodels.Product {

	result := viewmodels.Product{
		Id:          product.Id(),
		ImageUrl:    product.ImageUrl(),
		Name:        product.Name(),
		Type:        product.Typ(),
		Description: product.Description(),
		Price:       product.Price(),
	}

	return result
}
开发者ID:Ikanant,项目名称:GolangWebApp,代码行数:13,代码来源:products.go

示例3: Test_ConvertsProductToViewModel

func Test_ConvertsProductToViewModel(t *testing.T) {
	product := models.Product{}
	product.SetName("the name")
	product.SetDescriptionShort("the short description")
	product.SetDescriptionLong("the long description")
	product.SetPricePerLitre(42.127)
	product.SetPricePer10Litre(27.314)
	product.SetOrigin("the origin")
	product.SetIsOrganic(true)
	product.SetImageUrl("the image URL")
	product.SetId(42)

	result := ConvertProductToViewModel(product)

	if product.Name() != result.Name {
		t.Fail()
	}
	if product.DescriptionShort() != result.DescriptionShort {
		t.Fail()
	}
	if product.DescriptionLong() != result.DescriptionLong {
		t.Fail()
	}
	if product.PricePerLitre() != result.PricePerLitre {
		t.Fail()
	}
	if product.PricePer10Litre() != result.PricePer10Litre {
		t.Fail()
	}
	if product.Origin() != result.Origin {
		t.Fail()
	}
	if product.IsOrganic() != result.IsOrganic {
		t.Fail()
	}
	if product.ImageUrl() != result.ImageUrl {
		t.Fail()
	}
	if product.Id() != result.Id {
		t.Fail()
	}
}
开发者ID:obadonke,项目名称:psGoWebApp,代码行数:42,代码来源:product_test.go

示例4: EnsureData

func EnsureData(w http.ResponseWriter, c appengine.Context) {
	q := datastore.NewQuery("Product").Ancestor(productKey(c)).Limit(1)
	products := make([]models.Product, 0, 1)
	if _, err := q.GetAll(c, &products); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	var prodExists bool = false

	// if you only need e:
	for _, e := range products {
		c.Infof("Product:%v", e)
		prodExists = true
		break
	}

	if !prodExists {
		prod := new(models.Product)
		prod.Height = "6 - 8 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - June"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Strawberry-Gasana.JPG"
		prod.Description = "Everbearing. Great for containers! Or in the ground."
		prod.Name = "FRAGARIA (STRAWBERRY)  ‘GASANA’"
		prod.Class = "Fruit Crops"
		prod.Light = "Sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.68"

		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "6 - 8 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - June"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Strawberry-Gasana.JPG"
		prod.Description = "Everbearing. Great for containers! Or in the ground."
		prod.Name = "FRAGARIA (STRAWBERRY)  ‘GASANA’"
		prod.Class = "Fruit Crops"
		prod.Light = "Sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.68"

		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "9 - 12 inches"
		prod.HardinessZone = "4 - 8"
		prod.BloomTime = "Early Spring, Summer, Fall"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Achillea-Little-Moonshine-(2).JPG"
		prod.Description = "This exciting new introduction from Blooms of Bressingham has the bright yellow flowers of 'Moonshine' but at half the height! Great for containers and in the front of the border."
		prod.Name = "ACHILLEA  ‘LITTLE MOONSHINE’"
		prod.Class = "Hardy Perennials"
		prod.Light = "full sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.65"
		prod.Royalty = "$.16"
		prod.Colors = "Vibrant Yellow"
		prod.PatentStatus = "USPPAF"
		InsertProduct(c, *prod, w)

		prod = new(models.Product)
		prod.Height = "12 inches"
		prod.HardinessZone = "4 - 9"
		prod.BloomTime = "May - July"
		prod.ImageUrl = "http://www.jamesgreenhouses.com/_code/_dyn_images/products/Achillea-New-Vinage-Red-(4).JPG"
		prod.Description = "This new series from Ball Seed offers a compact and tidy habit with deep red flowers all summer."
		prod.Name = "ACHILLEA  NEW VINTAGE™ SERIES ‘RED’"
		prod.Class = "Hardy Perennials"
		prod.Light = "full sun"
		prod.PlugSize = "72"
		prod.PriceEach = "$.62"
		prod.Royalty = "$.08"
		prod.Colors = "Deep Red"
		prod.PatentStatus = "USPPAF"
		InsertProduct(c, *prod, w)
	}

}
开发者ID:ghstahl,项目名称:polybeegae,代码行数:79,代码来源:ensure_data.go

示例5: ConvertProductToViewModel

func ConvertProductToViewModel(product models.Product) viewmodels.Product {
	result := viewmodels.Product{
		Name:             product.Name(),
		DescriptionShort: product.DescriptionShort(),
		DescriptionLong:  product.DescriptionLong(),
		PricePerLitre:    product.PricePerLitre(),
		PricePer10Litre:  product.PricePer10Litre(),
		Origin:           product.Origin(),
		IsOrganic:        product.IsOrganic(),
		ImageUrl:         product.ImageUrl(),
		Id:               product.Id(),
	}

	return result
}
开发者ID:obadonke,项目名称:psGoWebApp,代码行数:15,代码来源:product.go


注:本文中的models.Product类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。