package restricted import ( "strconv" "git.ma-al.com/goc_daniel/b2b/app/service/meiliService" "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" "git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors" "github.com/gofiber/fiber/v3" ) type MeiliSearchHandler struct { meiliService *meiliService.MeiliService } func NewMeiliSearchHandler() *MeiliSearchHandler { meiliService := meiliService.New() return &MeiliSearchHandler{ meiliService: meiliService, } } func MeiliSearchHandlerRoutes(r fiber.Router) fiber.Router { handler := NewMeiliSearchHandler() r.Get("/test", handler.Test) return r } func (h *MeiliSearchHandler) Test(c fiber.Ctx) error { id_shop_attribute := c.Query("shopID") id_shop, err := strconv.Atoi(id_shop_attribute) if err != nil { return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)). JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute))) } id_lang, err := strconv.Atoi(c.Cookies("lang_id", "2")) 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.Test(uint(id_shop), uint(id_lang)) 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))) }