setup meili search
This commit is contained in:
55
app/delivery/web/api/restricted/meiliSearch.go
Normal file
55
app/delivery/web/api/restricted/meiliSearch.go
Normal file
@@ -0,0 +1,55 @@
|
||||
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)))
|
||||
}
|
||||
@@ -106,6 +106,10 @@ func (s *Server) Setup() error {
|
||||
menu := s.restricted.Group("/menu")
|
||||
restricted.MenuHandlerRoutes(menu)
|
||||
|
||||
// meili search (restricted)
|
||||
meiliSearch := s.restricted.Group("/meili-search")
|
||||
restricted.MeiliSearchHandlerRoutes(meiliSearch)
|
||||
|
||||
// // Restricted routes example
|
||||
// restricted := s.api.Group("/restricted")
|
||||
// restricted.Use(middleware.AuthMiddleware())
|
||||
|
||||
Reference in New Issue
Block a user