translation endpoint!
This commit is contained in:
@@ -32,8 +32,7 @@ func ProductDescriptionHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
|
||||
r.Get("/get-product-description", handler.GetProductDescription)
|
||||
r.Post("/save-product-description", handler.SaveProductDescription)
|
||||
// r.Get("/get-quarters", handler.GetQuarters)
|
||||
// r.Get("/get-issues", handler.GetIssues)
|
||||
r.Get("/translate-product-description", handler.TranslateProductDescription)
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -132,3 +131,54 @@ func (h *ProductDescriptionHandler) SaveProductDescription(c fiber.Ctx) error {
|
||||
"message": i18n.T_(c, "product_description.successfully_updated_fields"),
|
||||
})
|
||||
}
|
||||
|
||||
// GetProductDescription returns the product description for a given product ID
|
||||
func (h *ProductDescriptionHandler) TranslateProductDescription(c fiber.Ctx) error {
|
||||
userID, ok := c.Locals("userID").(uint)
|
||||
if !ok {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody), // possibly could return a different error
|
||||
})
|
||||
}
|
||||
|
||||
productID_attribute := c.Query("productID")
|
||||
productID, err := strconv.Atoi(productID_attribute)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute),
|
||||
})
|
||||
}
|
||||
|
||||
productShopID_attribute := c.Query("productShopID")
|
||||
productShopID, err := strconv.Atoi(productShopID_attribute)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute),
|
||||
})
|
||||
}
|
||||
|
||||
productFromLangID_attribute := c.Query("productFromLangID")
|
||||
productFromLangID, err := strconv.Atoi(productFromLangID_attribute)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute),
|
||||
})
|
||||
}
|
||||
|
||||
productToLangID_attribute := c.Query("productToLangID")
|
||||
productToLangID, err := strconv.Atoi(productToLangID_attribute)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute),
|
||||
})
|
||||
}
|
||||
|
||||
response, err := h.productDescriptionService.TranslateProductDescription(userID, uint(productID), uint(productShopID), uint(productFromLangID), uint(productToLangID))
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).JSON(fiber.Map{
|
||||
"error": responseErrors.GetErrorCode(c, err),
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user