本文整理汇总了Golang中github.com/asvins/warehouse/models.PurchaseProduct类的典型用法代码示例。如果您正苦于以下问题:Golang PurchaseProduct类的具体用法?Golang PurchaseProduct怎么用?Golang PurchaseProduct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PurchaseProduct类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FillPurchaseProductProductIdWithUrlValue
func FillPurchaseProductProductIdWithUrlValue(p *models.PurchaseProduct, params url.Values) error {
id, err := strconv.Atoi(params.Get("product_id"))
if err != nil {
return err
}
p.ProductId = id
return nil
}
示例2: retreivePurchaseProducts
func retreivePurchaseProducts(w http.ResponseWriter, r *http.Request) errors.Http {
pp := models.PurchaseProduct{}
if err := BuildStructFromQueryString(&pp, r.URL.Query()); err != nil {
return errors.BadRequest(err.Error())
}
pproducts, err := pp.Retreive(db)
if err != nil {
return errors.InternalServerError(err.Error())
}
if len(pproducts) == 0 {
return errors.NotFound("record not found")
}
rend.JSON(w, http.StatusOK, pproducts)
return nil
}
示例3: updatePurchaseProductOnQuantity
func updatePurchaseProductOnQuantity(w http.ResponseWriter, r *http.Request) errors.Http {
pp := models.PurchaseProduct{}
if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
return errors.BadRequest(err.Error())
}
quantity, err := strconv.Atoi(r.URL.Query().Get("quantity"))
if err != nil {
errors.BadRequest(err.Error())
}
if err := pp.UpdateQuantity(db, quantity); err != nil {
return errors.InternalServerError(err.Error())
}
rend.JSON(w, http.StatusOK, pp)
return nil
}
示例4: retreivePurchaseProductsById
func retreivePurchaseProductsById(w http.ResponseWriter, r *http.Request) errors.Http {
pp := models.PurchaseProduct{}
if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
return errors.BadRequest(err.Error())
}
pproducts, err := pp.Retreive(db)
if err != nil {
return errors.InternalServerError(err.Error())
}
if len(pproducts) != 1 {
return errors.NotFound("record not found")
}
rend.JSON(w, http.StatusOK, pproducts[0])
return nil
}
示例5: updatePurchaseProductOnValue
func updatePurchaseProductOnValue(w http.ResponseWriter, r *http.Request) errors.Http {
pp := models.PurchaseProduct{}
if err := FillPurchaseProductIdWithUrlValue(&pp, r.URL.Query()); err != nil {
return errors.BadRequest(err.Error())
}
value, err := strconv.ParseFloat(r.URL.Query().Get("value"), 64)
if err != nil {
errors.BadRequest(err.Error())
}
if err := pp.UpdateValue(db, value); err != nil {
return errors.InternalServerError(err.Error())
}
rend.JSON(w, http.StatusOK, pp)
return nil
}