bugs on variant id
This commit is contained in:
@@ -146,3 +146,48 @@ func (ctl *CatalogueController) GetProductBySKU(c *fiber.Ctx) error {
|
||||
"details": product,
|
||||
})
|
||||
}
|
||||
|
||||
// GetProductByImageID resolves a catalogue row by the id the ingest pipeline
|
||||
// treats as canonical, so a caller holding an ingest manifest can find the
|
||||
// catalogueid it needs to import the product into a shop.
|
||||
func (ctl *CatalogueController) GetProductByImageID(c *fiber.Ctx) error {
|
||||
brand := c.Query("brand")
|
||||
imageID := c.Query("image_id")
|
||||
if brand == "" || imageID == "" {
|
||||
return c.JSON(fiber.Map{
|
||||
"code": 400,
|
||||
"message": "brand and image_id are required",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
product, err := ctl.catalogueService.GetProductByImageID(brand, imageID)
|
||||
if err != nil {
|
||||
if errors.Is(err, repositories.ErrUnknownBrand) {
|
||||
return c.JSON(fiber.Map{
|
||||
"code": 400,
|
||||
"message": "Unknown brand: " + brand,
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
return c.JSON(fiber.Map{
|
||||
"code": 500,
|
||||
"message": "Failed to fetch catalogue product",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
if product == nil {
|
||||
return c.JSON(fiber.Map{
|
||||
"code": 404,
|
||||
"message": "Product not found",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"code": http.StatusOK,
|
||||
"message": "Success",
|
||||
"status": true,
|
||||
"details": product,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -416,6 +416,22 @@ func (ctl *ProductController) GetProductByVariant(c *fiber.Ctx) error {
|
||||
// nothing to work with.
|
||||
productID, _ := strconv.Atoi(c.Query("productid"))
|
||||
|
||||
// One of the two has to name something, and `variantid=0` names nothing.
|
||||
//
|
||||
// 0 is not a variant group — it is the value every UNGROUPED product
|
||||
// carries, so a query for it used to match the tenant's whole ungrouped
|
||||
// catalogue and return six unrelated products as each other's variants. The
|
||||
// ordering screen then had a list it could not choose from, and no order
|
||||
// could be placed. Refusing here turns that into one sentence naming the
|
||||
// parameter to send instead.
|
||||
if variantid <= 0 && productID <= 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest,
|
||||
"status": false,
|
||||
"message": "send productid (preferred) or a variantid above 0 — variantid 0 is not a variant group, it is what every ungrouped product carries",
|
||||
})
|
||||
}
|
||||
|
||||
result, err := ctl.productService.GetProductByVariant(tenantID, variantid, locationID, productID)
|
||||
|
||||
if err != nil {
|
||||
@@ -535,6 +551,33 @@ func (ctl *ProductController) CreateProductLocation(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateProductVariant puts a product into a variant group, or takes it out.
|
||||
//
|
||||
// variantid 0 means ungrouped and is allowed — it is a real thing to want. The
|
||||
// read path is what refuses to treat 0 as a group to search for.
|
||||
func (ctl *ProductController) UpdateProductVariant(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
Productid int `json:"productid"`
|
||||
Variantid int `json:"variantid"`
|
||||
}
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false, "message": "Invalid request body",
|
||||
})
|
||||
}
|
||||
if body.Productid <= 0 {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest, "status": false, "message": "productid is required",
|
||||
})
|
||||
}
|
||||
if err := ctl.productService.UpdateProductVariant(body.Productid, body.Variantid); err != nil {
|
||||
return c.Status(fiber.StatusConflict).JSON(fiber.Map{
|
||||
"code": http.StatusConflict, "status": false, "message": err.Error(),
|
||||
})
|
||||
}
|
||||
return c.JSON(fiber.Map{"code": http.StatusOK, "status": true, "message": "Success"})
|
||||
}
|
||||
|
||||
func (ctl *ProductController) CreateProductVariant(c *fiber.Ctx) error {
|
||||
var input models.Productvariant
|
||||
|
||||
|
||||
Reference in New Issue
Block a user