package access import "antrian-operasi/internal/shared" type AvailableMenuChildResponse struct { Title string `json:"title"` Icon string `json:"icon"` To string `json:"to"` Children []*AvailableMenuChildResponse `json:"children"` } type AvailableMenuResponse struct { ID string `json:"id"` Header string `json:"header"` Children []*AvailableMenuChildResponse `json:"children"` } 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 != "" { // 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{ ID: p.ID, Header: p.Name, Children: pageMap[p.ID].Children, }) } } return result } type UserRoleResponse struct { ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` HakAkses []string `json:"hak_akses"` } type ListUserRolePaginateResponse struct { Data []UserRoleResponse Paging shared.PaginationInfo } type ListRolePermissionPaginateResponse struct { Data []RolePermissionModel Paging shared.PaginationInfo } type AccessPage struct { ID string `json:"id" binding:"required"` Page string `json:"page"` IsActive bool `json:"is_active" binding:"required"` Sort int `json:"sort"` ParentId *string `json:"parent_id" binding:"uuid"` } type DetailRolePageResponse struct { ID string `json:"id" db:"id" binding:"required,uuid"` Name string `json:"name" db:"name"` Status bool `json:"status" db:"is_active"` AccessPage []AccessPage `json:"access_page"` }