Merge branch 'main' of ssh://git.ma-al.com:8822/goc_daniel/b2b into product-procedures
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"git.ma-al.com/goc_daniel/b2b/app/config"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/authService"
|
||||
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
@@ -60,8 +61,8 @@ func AuthMiddleware() fiber.Handler {
|
||||
}
|
||||
|
||||
// Set user in context
|
||||
c.Locals("user", user.ToSession())
|
||||
c.Locals("userID", user.ID)
|
||||
c.Locals(constdata.USER_LOCALES_NAME, user.ToSession())
|
||||
c.Locals(constdata.USER_LOCALES_ID, user.ID)
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
45
app/delivery/web/api/public/routing.go
Normal file
45
app/delivery/web/api/public/routing.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package public
|
||||
|
||||
import (
|
||||
"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 RoutingHandler struct {
|
||||
menuService *menuService.MenuService
|
||||
}
|
||||
|
||||
func NewRoutingHandler() *RoutingHandler {
|
||||
menuService := menuService.New()
|
||||
return &RoutingHandler{
|
||||
menuService: menuService,
|
||||
}
|
||||
}
|
||||
|
||||
// AuthHandlerRoutes registers all auth routes
|
||||
func RoutingHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
handler := NewRoutingHandler()
|
||||
|
||||
r.Get("/get-routes", handler.GetRouting)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (h *RoutingHandler) GetRouting(c fiber.Ctx) error {
|
||||
lang_id, ok := c.Locals("langID").(uint)
|
||||
if !ok {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||
}
|
||||
menu, err := h.menuService.GetRoutes(lang_id)
|
||||
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)))
|
||||
}
|
||||
@@ -60,8 +60,8 @@ func (h *ListProductsHandler) GetListing(c fiber.Ctx) error {
|
||||
var columnMappingGetListing map[string]string = map[string]string{
|
||||
"product_id": "ps.id_product",
|
||||
"name": "pl.name",
|
||||
"reference": "ps.reference",
|
||||
"reference": "p.reference",
|
||||
"category_name": "cl.name",
|
||||
"id_category": "cp.id_category",
|
||||
"category_id": "cp.id_category",
|
||||
"quantity": "sa.quantity",
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ func MenuHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
handler := NewMenuHandler()
|
||||
|
||||
r.Get("/get-menu", handler.GetMenu)
|
||||
r.Get("/get-routes", handler.GetRouting)
|
||||
r.Get("/get-top-menu", handler.GetTopMenu)
|
||||
|
||||
return r
|
||||
@@ -45,21 +44,6 @@ func (h *MenuHandler) GetMenu(c fiber.Ctx) error {
|
||||
return c.JSON(response.Make(&menu, 0, i18n.T_(c, response.Message_OK)))
|
||||
}
|
||||
|
||||
func (h *MenuHandler) GetRouting(c fiber.Ctx) error {
|
||||
lang_id, ok := c.Locals("langID").(uint)
|
||||
if !ok {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||
}
|
||||
menu, err := h.menuService.GetRoutes(lang_id)
|
||||
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)))
|
||||
}
|
||||
|
||||
func (h *MenuHandler) GetTopMenu(c fiber.Ctx) error {
|
||||
lang_id, ok := c.Locals("langID").(uint)
|
||||
if !ok {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package restricted
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/service/meiliService"
|
||||
searchservice "git.ma-al.com/goc_daniel/b2b/app/service/searchService"
|
||||
"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"
|
||||
@@ -12,26 +14,23 @@ import (
|
||||
)
|
||||
|
||||
type MeiliSearchHandler struct {
|
||||
meiliService *meiliService.MeiliService
|
||||
meiliService *meiliService.MeiliService
|
||||
searchService *searchservice.SearchService
|
||||
}
|
||||
|
||||
func NewMeiliSearchHandler() *MeiliSearchHandler {
|
||||
meiliService := meiliService.New()
|
||||
return &MeiliSearchHandler{
|
||||
meiliService: meiliService,
|
||||
meiliService: meiliService.New(),
|
||||
searchService: searchservice.New(),
|
||||
}
|
||||
}
|
||||
|
||||
func MeiliSearchHandlerRoutes(r fiber.Router) fiber.Router {
|
||||
handler := NewMeiliSearchHandler()
|
||||
|
||||
// for testing purposes only. Must be removed before proper release.
|
||||
r.Get("/create-index", handler.CreateIndex)
|
||||
r.Get("/test", handler.Test)
|
||||
r.Get("/settings", handler.GetSettings)
|
||||
|
||||
// for all users
|
||||
r.Get("/search", handler.Search)
|
||||
r.Post("/search", handler.Search)
|
||||
r.Post("/settings", handler.GetSettings)
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -45,6 +44,7 @@ func (h *MeiliSearchHandler) CreateIndex(c fiber.Ctx) error {
|
||||
|
||||
err := h.meiliService.CreateIndex(id_lang)
|
||||
if err != nil {
|
||||
fmt.Printf("CreateIndex error: %v\n", err)
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
@@ -53,22 +53,6 @@ func (h *MeiliSearchHandler) CreateIndex(c fiber.Ctx) error {
|
||||
return c.JSON(response.Make(¬hing, 0, i18n.T_(c, response.Message_OK)))
|
||||
}
|
||||
|
||||
func (h *MeiliSearchHandler) Test(c fiber.Ctx) error {
|
||||
id_lang, ok := c.Locals("langID").(uint)
|
||||
if !ok {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||
}
|
||||
|
||||
test, err := h.meiliService.Test(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)))
|
||||
}
|
||||
|
||||
func (h *MeiliSearchHandler) Search(c fiber.Ctx) error {
|
||||
id_lang, ok := c.Locals("langID").(uint)
|
||||
if !ok {
|
||||
@@ -76,22 +60,31 @@ func (h *MeiliSearchHandler) Search(c fiber.Ctx) error {
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||
}
|
||||
|
||||
query := c.Query("query")
|
||||
index := meiliService.GetIndexName(id_lang)
|
||||
|
||||
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)))
|
||||
var body map[string]interface{}
|
||||
if err := json.Unmarshal(c.Body(), &body); err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrInvalidBody)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrInvalidBody)))
|
||||
}
|
||||
|
||||
meili_response, err := h.meiliService.Search(id_lang, query, uint(id_category))
|
||||
result, err := h.searchService.Search(index, c.Body(), 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(&meili_response, 0, i18n.T_(c, response.Message_OK)))
|
||||
if h.searchService.IsIndexNotFound(result.Body) {
|
||||
if createErr := h.meiliService.CreateIndex(id_lang); createErr == nil {
|
||||
result, err = h.searchService.Search(index, c.Body(), id_lang)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.Status(result.StatusCode).Send(result.Body)
|
||||
}
|
||||
|
||||
func (h *MeiliSearchHandler) GetSettings(c fiber.Ctx) error {
|
||||
@@ -101,11 +94,13 @@ func (h *MeiliSearchHandler) GetSettings(c fiber.Ctx) error {
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
|
||||
}
|
||||
|
||||
settings, err := h.meiliService.GetIndexSettings(id_lang)
|
||||
index := meiliService.GetIndexName(id_lang)
|
||||
|
||||
result, err := h.searchService.GetIndexSettings(index)
|
||||
if err != nil {
|
||||
return c.Status(responseErrors.GetErrorStatus(err)).
|
||||
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err)))
|
||||
}
|
||||
|
||||
return c.JSON(response.Make(&settings, 0, i18n.T_(c, response.Message_OK)))
|
||||
return c.Status(result.StatusCode).Send(result.Body)
|
||||
}
|
||||
@@ -16,9 +16,7 @@ import (
|
||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/web/api/restricted"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/delivery/web/general"
|
||||
|
||||
// "github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
// "github.com/gofiber/fiber/v3/middleware/filesystem"
|
||||
"github.com/gofiber/fiber/v3/middleware/logger"
|
||||
"github.com/gofiber/fiber/v3/middleware/recover"
|
||||
)
|
||||
@@ -89,6 +87,9 @@ func (s *Server) Setup() error {
|
||||
auth := s.public.Group("/auth")
|
||||
public.AuthHandlerRoutes(auth)
|
||||
|
||||
menuRouting := s.public.Group("/menu")
|
||||
public.RoutingHandlerRoutes(menuRouting)
|
||||
|
||||
// product translation routes (restricted)
|
||||
productTranslation := s.restricted.Group("/product-translation")
|
||||
restricted.ProductTranslationHandlerRoutes(productTranslation)
|
||||
@@ -109,7 +110,7 @@ func (s *Server) Setup() error {
|
||||
restricted.MenuHandlerRoutes(menu)
|
||||
|
||||
// meili search (restricted)
|
||||
meiliSearch := s.restricted.Group("/meili-search")
|
||||
meiliSearch := s.restricted.Group("/search")
|
||||
restricted.MeiliSearchHandlerRoutes(meiliSearch)
|
||||
|
||||
// carts (restricted)
|
||||
|
||||
Reference in New Issue
Block a user