add top menu
This commit is contained in:
@@ -3,12 +3,9 @@ package menuService
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"git.ma-al.com/goc_daniel/b2b/app/db"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/model/prestadb"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/repos/categoriesRepo"
|
||||
routesRepo "git.ma-al.com/goc_daniel/b2b/app/repos/routesRepo"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/jsonprint"
|
||||
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
|
||||
)
|
||||
|
||||
@@ -77,17 +74,6 @@ func (s *MenuService) createTree(index int, all_categories *([]model.ScannedCate
|
||||
}
|
||||
|
||||
func (s *MenuService) GetRoutes(id_lang uint) ([]model.Route, error) {
|
||||
|
||||
type XX struct {
|
||||
prestadb.PsProduct
|
||||
// PsProductLang prestadb.PsProductLang `gorm:"foreignKey:IDProduct;references:IDProduct"`
|
||||
// PSProductAttribute prestadb.PsProductAttribute `gorm:"foreignKey:IDProduct;references:IDProduct"`
|
||||
}
|
||||
product := XX{}
|
||||
db.Get().Debug().Find(&product, prestadb.PsCategoryProduct{IDProduct: 53})
|
||||
// fmt.Printf("%v\n nnnnnnnn", product)
|
||||
jsonprint.Print(product)
|
||||
|
||||
return s.routesRepo.GetRoutes(id_lang)
|
||||
}
|
||||
|
||||
@@ -111,3 +97,34 @@ type ByPosition []ChildWithPosition
|
||||
func (a ByPosition) Len() int { return len(a) }
|
||||
func (a ByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByPosition) Less(i, j int) bool { return a[i].Position < a[j].Position }
|
||||
|
||||
func (s *MenuService) GetTopMenu(id uint) ([]model.B2BTopMenu, error) {
|
||||
menuMap := make(map[int]*model.B2BTopMenu)
|
||||
var roots []model.B2BTopMenu
|
||||
|
||||
items, err := s.routesRepo.GetTopMenu(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Build the map first
|
||||
for i := range items {
|
||||
items[i].Children = []model.B2BTopMenu{}
|
||||
menuMap[items[i].MenuID] = &items[i]
|
||||
}
|
||||
|
||||
// Then link children to parents
|
||||
for _, item := range menuMap {
|
||||
if item.ParentID != nil && *item.ParentID != 0 {
|
||||
parent, exists := menuMap[*item.ParentID]
|
||||
if exists {
|
||||
parent.Children = append(parent.Children, *item)
|
||||
}
|
||||
} else {
|
||||
// This is a root item
|
||||
roots = append(roots, *item)
|
||||
}
|
||||
}
|
||||
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user