package restricted import ( "strconv" "git.ma-al.com/goc_daniel/b2b/app/service/menuService" "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 MenuHandler struct { menuService *menuService.MenuService } func NewMenuHandler() *MenuHandler { menuService := menuService.New() return &MenuHandler{ menuService: menuService, } } func MenuHandlerRoutes(r fiber.Router) fiber.Router { handler := NewMenuHandler() r.Get("/get-menu", handler.GetMenu) return r } func (h *MenuHandler) GetMenu(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))) } menu, err := h.menuService.GetMenu(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(&menu, 0, i18n.T_(c, response.Message_OK))) }