fix : error nil pointer endpoint access menu
This commit is contained in:
@@ -17,21 +17,33 @@ type AvailableMenuResponse struct {
|
||||
|
||||
func MapMenuModelToResponse(pages []RolePageModel) []AvailableMenuResponse {
|
||||
pageMap := make(map[string]*AvailableMenuChildResponse)
|
||||
childrenMap := make(map[string][]*AvailableMenuChildResponse)
|
||||
|
||||
var result []AvailableMenuResponse
|
||||
|
||||
// First pass: create all menu items
|
||||
for _, p := range pages {
|
||||
pageMap[p.ID] = &AvailableMenuChildResponse{
|
||||
Title: p.Name,
|
||||
Icon: p.Icon.String,
|
||||
To: p.Url.String,
|
||||
}
|
||||
}
|
||||
|
||||
// Second pass: build parent-child relationships
|
||||
for _, p := range pages {
|
||||
if p.ParentId.String != "" {
|
||||
pageMap[p.ParentId.String].Children = append(pageMap[p.ParentId.String].Children, pageMap[p.ID])
|
||||
// Check if parent exists before adding child
|
||||
if parent, exists := pageMap[p.ParentId.String]; exists {
|
||||
parent.Children = append(parent.Children, pageMap[p.ID])
|
||||
}
|
||||
} else {
|
||||
// Track root items
|
||||
childrenMap[p.ID] = pageMap[p.ID].Children
|
||||
}
|
||||
}
|
||||
|
||||
// Third pass: build result with root items only
|
||||
for _, p := range pages {
|
||||
if p.ParentId.String == "" {
|
||||
result = append(result, AvailableMenuResponse{
|
||||
|
||||
Reference in New Issue
Block a user