console categories
This commit is contained in:
@@ -787,6 +787,48 @@ func (ctl *ProductController) GetTenantCategories(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// Recategorise re-files a tenant's products in bulk.
|
||||
//
|
||||
// PUT and not POST: it changes rows that already exist and creates none. The
|
||||
// response carries how many rows actually moved, which is the only way a caller
|
||||
// can tell "all done" from "every id I sent was wrong".
|
||||
func (ctl *ProductController) Recategorise(c *fiber.Ctx) error {
|
||||
var body struct {
|
||||
Tenantid int `json:"tenantid"`
|
||||
Updates []models.ProductCategoryUpdate `json:"updates"`
|
||||
}
|
||||
if err := c.BodyParser(&body); err != nil {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "invalid body",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
if body.Tenantid == 0 {
|
||||
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "tenantid is required",
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
moved, err := ctl.productService.RecategoriseProducts(body.Tenantid, body.Updates)
|
||||
if err != nil {
|
||||
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{
|
||||
"code": http.StatusInternalServerError,
|
||||
"message": err.Error(),
|
||||
"status": false,
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"code": http.StatusOK,
|
||||
"message": "Success",
|
||||
"status": true,
|
||||
"details": fiber.Map{"moved": moved},
|
||||
})
|
||||
}
|
||||
|
||||
// ResolveCategories exchanges category names for this tenant's category ids.
|
||||
//
|
||||
// POST, not GET, because it CREATES the categories it cannot find — a sheet
|
||||
|
||||
Reference in New Issue
Block a user