some debugging

This commit is contained in:
Daniel Goc
2026-03-25 10:42:25 +01:00
parent e279899e49
commit f81eb84499
17 changed files with 70 additions and 67 deletions

View File

@@ -25,7 +25,7 @@ func NewMeiliSearchHandler() *MeiliSearchHandler {
func MeiliSearchHandlerRoutes(r fiber.Router) fiber.Router {
handler := NewMeiliSearchHandler()
// for superadmin only
// for testing purposes only. Must be removed before proper release.
r.Get("/create-index", handler.CreateIndex)
r.Get("/test", handler.Test)
@@ -84,32 +84,32 @@ func (h *MeiliSearchHandler) Search(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
id_category_attribute := c.Query("id_category")
id_category_attribute := c.Query("id_category", "0")
id_category, err := strconv.Atoi(id_category_attribute)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
price_lower_bound_attribute := c.Query("price_lower_bound")
price_lower_bound_attribute := c.Query("price_lower_bound", "-1.0")
price_lower_bound, err := strconv.ParseFloat(price_lower_bound_attribute, 64)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
price_upper_bound_attribute := c.Query("price_upper_bound")
price_upper_bound_attribute := c.Query("price_upper_bound", "-1.0")
price_upper_bound, err := strconv.ParseFloat(price_upper_bound_attribute, 64)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
test, err := h.meiliService.Search(id_lang, query, uint(limit), uint(id_category), price_lower_bound, price_upper_bound)
meili_response, err := h.meiliService.Search(id_lang, query, uint(limit), uint(id_category), price_lower_bound, price_upper_bound)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
}
return c.JSON(response.Make(&test, 0, i18n.T_(c, response.Message_OK)))
return c.JSON(response.Make(&meili_response, 0, i18n.T_(c, response.Message_OK)))
}

View File

@@ -4,7 +4,7 @@ import (
"strconv"
"git.ma-al.com/goc_daniel/b2b/app/config"
"git.ma-al.com/goc_daniel/b2b/app/service/productDescriptionService"
"git.ma-al.com/goc_daniel/b2b/app/service/productTranslationService"
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
"git.ma-al.com/goc_daniel/b2b/app/utils/nullable"
"git.ma-al.com/goc_daniel/b2b/app/utils/response"
@@ -13,24 +13,24 @@ import (
"github.com/gofiber/fiber/v3"
)
// ProductDescriptionHandler handles endpoints that receive, save and translate product descriptions.
type ProductDescriptionHandler struct {
productDescriptionService *productDescriptionService.ProductDescriptionService
// ProductTranslationHandler handles endpoints that receive, save and translate product descriptions.
type ProductTranslationHandler struct {
productTranslationService *productTranslationService.ProductTranslationService
config *config.Config
}
// NewProductDescriptionHandler creates a new ProductDescriptionHandler instance
func NewProductDescriptionHandler() *ProductDescriptionHandler {
productDescriptionService := productDescriptionService.New()
return &ProductDescriptionHandler{
productDescriptionService: productDescriptionService,
// NewProductTranslationHandler creates a new ProductTranslationHandler instance
func NewProductTranslationHandler() *ProductTranslationHandler {
productTranslationService := productTranslationService.New()
return &ProductTranslationHandler{
productTranslationService: productTranslationService,
config: config.Get(),
}
}
// ProductDescriptionRoutes registers all product description routes
func ProductDescriptionHandlerRoutes(r fiber.Router) fiber.Router {
handler := NewProductDescriptionHandler()
// ProductTranslationRoutes registers all product description routes
func ProductTranslationHandlerRoutes(r fiber.Router) fiber.Router {
handler := NewProductTranslationHandler()
r.Get("/get-product-description", handler.GetProductDescription)
r.Post("/save-product-description", handler.SaveProductDescription)
@@ -40,7 +40,7 @@ func ProductDescriptionHandlerRoutes(r fiber.Router) fiber.Router {
}
// GetProductDescription returns the product description for a given product ID
func (h *ProductDescriptionHandler) GetProductDescription(c fiber.Ctx) error {
func (h *ProductTranslationHandler) GetProductDescription(c fiber.Ctx) error {
userID, ok := c.Locals("userID").(uint)
if !ok {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
@@ -61,7 +61,7 @@ func (h *ProductDescriptionHandler) GetProductDescription(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
description, err := h.productDescriptionService.GetProductDescription(userID, uint(productID), uint(productLangID))
description, err := h.productTranslationService.GetProductDescription(userID, uint(productID), uint(productLangID))
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
@@ -71,7 +71,7 @@ func (h *ProductDescriptionHandler) GetProductDescription(c fiber.Ctx) error {
}
// SaveProductDescription saves the description for a given product ID, in given language
func (h *ProductDescriptionHandler) SaveProductDescription(c fiber.Ctx) error {
func (h *ProductTranslationHandler) SaveProductDescription(c fiber.Ctx) error {
userID, ok := c.Locals("userID").(uint)
if !ok {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
@@ -98,7 +98,7 @@ func (h *ProductDescriptionHandler) SaveProductDescription(c fiber.Ctx) error {
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
}
err = h.productDescriptionService.SaveProductDescription(userID, uint(productID), uint(productLangID), updates)
err = h.productTranslationService.SaveProductDescription(userID, uint(productID), uint(productLangID), updates)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
@@ -108,7 +108,7 @@ func (h *ProductDescriptionHandler) SaveProductDescription(c fiber.Ctx) error {
}
// TranslateProductDescription returns translated product description
func (h *ProductDescriptionHandler) TranslateProductDescription(c fiber.Ctx) error {
func (h *ProductTranslationHandler) TranslateProductDescription(c fiber.Ctx) error {
userID, ok := c.Locals("userID").(uint)
if !ok {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
@@ -142,7 +142,7 @@ func (h *ProductDescriptionHandler) TranslateProductDescription(c fiber.Ctx) err
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
description, err := h.productDescriptionService.TranslateProductDescription(userID, uint(productID), uint(productFromLangID), uint(productToLangID), aiModel)
description, err := h.productTranslationService.TranslateProductDescription(userID, uint(productID), uint(productFromLangID), uint(productToLangID), aiModel)
if err != nil {
return c.Status(responseErrors.GetErrorStatus(err)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))