Merge branch 'main' of ssh://git.ma-al.com:8822/goc_daniel/b2b into order-actions

This commit is contained in:
2026-04-17 11:45:34 +02:00
11 changed files with 202 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ package restricted
import ( import (
"strconv" "strconv"
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware"
"git.ma-al.com/goc_daniel/b2b/app/delivery/middleware/perms"
"git.ma-al.com/goc_daniel/b2b/app/service/menuService" "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/i18n"
"git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor" "git.ma-al.com/goc_daniel/b2b/app/utils/localeExtractor"
@@ -30,6 +32,7 @@ func MenuHandlerRoutes(r fiber.Router) fiber.Router {
r.Get("/get-category-tree", handler.GetCategoryTree) r.Get("/get-category-tree", handler.GetCategoryTree)
r.Get("/get-breadcrumb", handler.GetBreadcrumb) r.Get("/get-breadcrumb", handler.GetBreadcrumb)
r.Get("/get-top-menu", handler.GetTopMenu) r.Get("/get-top-menu", handler.GetTopMenu)
r.Get("/get-customer-management-menu", middleware.Require(perms.UserReadAny), handler.GetCustomerManagementMenu)
return r return r
} }
@@ -119,3 +122,18 @@ func (h *MenuHandler) GetTopMenu(c fiber.Ctx) error {
return c.JSON(response.Make(&menu, len(menu), i18n.T_(c, response.Message_OK))) return c.JSON(response.Make(&menu, len(menu), i18n.T_(c, response.Message_OK)))
} }
func (h *MenuHandler) GetCustomerManagementMenu(c fiber.Ctx) error {
langId, ok := localeExtractor.GetLangID(c)
if !ok {
return c.Status(responseErrors.GetErrorStatus(responseErrors.ErrBadAttribute)).
JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrBadAttribute)))
}
menu, err := h.menuService.GetCustomerManagementMenu(langId)
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, len(menu), i18n.T_(c, response.Message_OK)))
}

View File

@@ -2,7 +2,7 @@ package model
import "encoding/json" import "encoding/json"
type B2BTopMenu struct { type B2BMenu struct {
MenuID int `gorm:"column:menu_id;primaryKey;autoIncrement" json:"menu_id"` MenuID int `gorm:"column:menu_id;primaryKey;autoIncrement" json:"menu_id"`
Label json.RawMessage `gorm:"column:label;type:longtext;not null;default:'{}'" json:"label"` Label json.RawMessage `gorm:"column:label;type:longtext;not null;default:'{}'" json:"label"`
ParentID *int `gorm:"column:parent_id;index:FK_b2b_top_menu_parent_id" json:"parent_id,omitempty"` ParentID *int `gorm:"column:parent_id;index:FK_b2b_top_menu_parent_id" json:"parent_id,omitempty"`
@@ -10,10 +10,22 @@ type B2BTopMenu struct {
Active int8 `gorm:"column:active;type:tinyint;not null;default:1" json:"active"` Active int8 `gorm:"column:active;type:tinyint;not null;default:1" json:"active"`
Position int `gorm:"column:position;not null;default:1" json:"position"` Position int `gorm:"column:position;not null;default:1" json:"position"`
Parent *B2BTopMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"` Parent *B2BMenu `gorm:"foreignKey:ParentID;references:MenuID;constraint:OnDelete:RESTRICT,OnUpdate:RESTRICT" json:"parent,omitempty"`
Children []*B2BTopMenu `gorm:"foreignKey:ParentID" json:"children,omitempty"` Children []*B2BMenu `gorm:"foreignKey:ParentID" json:"children,omitempty"`
}
type B2BTopMenu struct {
B2BMenu
} }
func (B2BTopMenu) TableName() string { func (B2BTopMenu) TableName() string {
return "b2b_top_menu" return "b2b_top_menu"
} }
type B2BCustomerManagementMenu struct {
B2BMenu
}
func (B2BCustomerManagementMenu) TableName() string {
return "b2b_customer_management_menu"
}

View File

@@ -9,6 +9,7 @@ import (
type UIRoutesRepo interface { type UIRoutesRepo interface {
GetRoutes(langId uint, roleId uint) ([]model.Route, error) GetRoutes(langId uint, roleId uint) ([]model.Route, error)
GetTopMenu(id uint, roleId uint) ([]model.B2BTopMenu, error) GetTopMenu(id uint, roleId uint) ([]model.B2BTopMenu, error)
GetCustomerManagementMenu(langId uint) ([]model.B2BCustomerManagementMenu, error)
} }
type RoutesRepo struct{} type RoutesRepo struct{}
@@ -38,10 +39,23 @@ func (p *RoutesRepo) GetTopMenu(langId uint, roleId uint) ([]model.B2BTopMenu, e
Get(). Get().
Model(model.B2BTopMenu{}). Model(model.B2BTopMenu{}).
Joins("JOIN b2b_top_menu_roles tmr ON tmr.top_menu_id = b2b_top_menu.menu_id"). Joins("JOIN b2b_top_menu_roles tmr ON tmr.top_menu_id = b2b_top_menu.menu_id").
Where(model.B2BTopMenu{Active: 1}). Where(model.B2BTopMenu{B2BMenu: model.B2BMenu{Active: 1}}).
Where("tmr.role_id = ?", roleId). Where("tmr.role_id = ?", roleId).
Order("b2b_top_menu.parent_id ASC, b2b_top_menu.position ASC"). Order("b2b_top_menu.parent_id ASC, b2b_top_menu.position ASC").
Find(&menus).Error Find(&menus).Error
return menus, err return menus, err
} }
func (p *RoutesRepo) GetCustomerManagementMenu(langId uint) ([]model.B2BCustomerManagementMenu, error) {
var menus []model.B2BCustomerManagementMenu
err := db.
Get().
Model(model.B2BCustomerManagementMenu{}).
Where(model.B2BCustomerManagementMenu{B2BMenu: model.B2BMenu{Active: 1}}).
Order("b2b_customer_management_menu.parent_id ASC, b2b_customer_management_menu.position ASC").
Find(&menus).Error
return menus, err
}

View File

@@ -10,6 +10,7 @@ import (
routesRepo "git.ma-al.com/goc_daniel/b2b/app/repos/routesRepo" routesRepo "git.ma-al.com/goc_daniel/b2b/app/repos/routesRepo"
constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data" constdata "git.ma-al.com/goc_daniel/b2b/app/utils/const_data"
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n" "git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
"git.ma-al.com/goc_daniel/b2b/app/utils/logger"
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors" "git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
) )
@@ -193,18 +194,52 @@ func (s *MenuService) GetBreadcrumb(root_category_id uint, start_category_id uin
return breadcrumb, nil return breadcrumb, nil
} }
func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BTopMenu, error) { func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BMenu, error) {
items, err := s.routesRepo.GetTopMenu(languageId, roleId) items, err := s.routesRepo.GetTopMenu(languageId, roleId)
if err != nil { if err != nil {
logger.Error("failed to get top menu",
"handler", "ManuService.GetTopMenu",
"language_id", languageId,
"role_id", roleId,
"error", err.Error(),
)
return nil, err return nil, err
} }
menuMap := make(map[int]*model.B2BTopMenu, len(items)) menus := make([]model.B2BMenu, len(items))
roots := make([]*model.B2BTopMenu, 0) for i := range items {
menus[i] = items[i].B2BMenu
}
return buildMenu(menus), nil
}
func (s *MenuService) GetCustomerManagementMenu(languageId uint) ([]*model.B2BMenu, error) {
items, err := s.routesRepo.GetCustomerManagementMenu(languageId)
if err != nil {
logger.Error("failed to get customer management menu",
"handler", "ManuService.GetCustomerManagementMenu",
"language_id", languageId,
"error", err.Error(),
)
return nil, err
}
menus := make([]model.B2BMenu, len(items))
for i := range items {
menus[i] = items[i].B2BMenu
}
return buildMenu(menus), nil
}
func buildMenu(items []model.B2BMenu) []*model.B2BMenu {
menuMap := make(map[int]*model.B2BMenu, len(items))
roots := make([]*model.B2BMenu, 0)
for i := range items { for i := range items {
menu := &items[i] menu := &items[i]
menu.Children = make([]*model.B2BTopMenu, 0) menu.Children = make([]*model.B2BMenu, 0)
menuMap[menu.MenuID] = menu menuMap[menu.MenuID] = menu
} }
@@ -226,7 +261,7 @@ func (s *MenuService) GetTopMenu(languageId uint, roleId uint) ([]*model.B2BTopM
parent.Children = append(parent.Children, menu) parent.Children = append(parent.Children, menu)
} }
return roots, nil return roots
} }
func (s *MenuService) appendAdditional(all_categories *[]model.ScannedCategory, id_lang uint, iso_code string) { func (s *MenuService) appendAdditional(all_categories *[]model.ScannedCategory, id_lang uint, iso_code string) {

View File

@@ -0,0 +1,22 @@
info:
name: Breadcrumb
type: http
seq: 1
http:
method: GET
url: http://localhost:3000/api/v1/restricted/menu/get-breadcrumb?root_category_id=2&category_id=13
params:
- name: root_category_id
value: "2"
type: query
- name: category_id
value: "13"
type: query
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

View File

@@ -0,0 +1,19 @@
info:
name: Category tree
type: http
seq: 2
http:
method: GET
url: http://localhost:3000/api/v1/restricted/menu/get-category-tree?root_category_id=2
params:
- name: root_category_id
value: "2"
type: query
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

View File

@@ -0,0 +1,15 @@
info:
name: Top Customer Management Menu
type: http
seq: 4
http:
method: GET
url: "{{bas_url}}/restricted/menu/get-customer-management-menu"
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

View File

@@ -0,0 +1,15 @@
info:
name: Top Menu
type: http
seq: 3
http:
method: GET
url: "{{bas_url}}/restricted/menu/get-top-menu"
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5

View File

@@ -0,0 +1,7 @@
info:
name: menu
type: folder
seq: 12
request:
auth: inherit

View File

@@ -42,9 +42,32 @@ INSERT IGNORE INTO `b2b_top_menu` (`menu_id`, `label`, `parent_id`, `params`, `a
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1), (3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1); (9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
CREATE TABLE IF NOT EXISTS b2b_customer_management_menu (
menu_id INT AUTO_INCREMENT NOT NULL,
label LONGTEXT NOT NULL DEFAULT '{}',
parent_id INT NULL DEFAULT NULL,
params LONGTEXT NOT NULL DEFAULT '{}',
active TINYINT NOT NULL DEFAULT 1,
position INT NOT NULL DEFAULT 1,
PRIMARY KEY (menu_id),
CONSTRAINT FK_b2b_customer_management_menu_parent_id FOREIGN KEY (parent_id)
REFERENCES b2b_customer_management_menu (menu_id)
ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX FK_b2b_customer_management_menu_parent_id_idx (parent_id ASC)
) ENGINE = InnoDB;
INSERT IGNORE INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES
(1, JSON_COMPACT('{"name":"root","trans":{"pl":{"label":"Menu główne"},"en":{"label":"Main Menu"},"de":{"label":"Hauptmenü"}}}'),NULL,JSON_COMPACT('{}'),1,1),
(3, JSON_COMPACT('{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}'),1,JSON_COMPACT('{}'),1,1),
(9, JSON_COMPACT('{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}'),3,JSON_COMPACT('{"route": {"name": "home", "params":{"locale": ""}}}'),1,1);
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (1, '{"name":"root","trans":{"pl":{"label":"Menu główne"},"en":{"label":"Main Menu"},"de":{"label":"Hauptmenü"}}}', NULL, '{}', 1, 1);
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (3, '{"name":"admin-products","trans":{"pl":{"label":"admin-products"},"en":{"label":"admin-products"},"de":{"label":"admin-products"}}}', 1, '{}', 1, 1);
INSERT INTO `b2b_customer_management_menu` (`menu_id`, `label`, `parent_id`, `params`, `active`, `position`) VALUES (9, '{"name":"carts","trans":{"pl":{"label":"Koszyki"},"en":{"label":"Carts"},"de":{"label":"Warenkörbe"}}}', 3, '{"route":{"name":"home","params":{"locale":""}}}', 1, 1);
-- +goose Down -- +goose Down
DROP TABLE IF EXISTS b2b_routes; DROP TABLE IF EXISTS b2b_routes;
DROP TABLE IF EXISTS b2b_top_menu; DROP TABLE IF EXISTS b2b_top_menu;
DROP TABLE IF EXISTS b2b_customer_management_menu;
DROP FUNCTION IF EXISTS `slugify_eu`; DROP FUNCTION IF EXISTS `slugify_eu`;

View File

@@ -12,6 +12,19 @@ INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('admin','2');
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3'); INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('super_admin','3');
INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('unlogged','4'); INSERT INTO `b2b_roles` (`name`, `id`) VALUES ('unlogged','4');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '1');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '1');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '1');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '2');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '2');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '2');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '3');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '3');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '3');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (1, '4');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (3, '4');
INSERT INTO `b2b_top_menu_roles` (`top_menu_id`, `role_id`) VALUES (9, '4');
-- insert sample admin user admin@ma-al.com/Maal12345678 -- insert sample admin user admin@ma-al.com/Maal12345678
INSERT IGNORE INTO b2b_customers (id, email, password, first_name, last_name, role_id, provider, provider_id, avatar_url, is_active, email_verified, email_verification_token, email_verification_expires, password_reset_token, password_reset_expires, last_password_reset_request, last_login_at, lang_id, country_id, created_at, updated_at, deleted_at) INSERT IGNORE INTO b2b_customers (id, email, password, first_name, last_name, role_id, provider, provider_id, avatar_url, is_active, email_verified, email_verification_token, email_verification_expires, password_reset_token, password_reset_expires, last_password_reset_request, last_login_at, lang_id, country_id, created_at, updated_at, deleted_at)