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 }
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 }