bugs on variant id

This commit is contained in:
2026-08-29 16:45:47 +05:30
parent c5109bf216
commit 76554d26e5
8 changed files with 204 additions and 1 deletions

View File

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