59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
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)
|
|
|
|
var result []AvailableMenuResponse
|
|
|
|
for _, p := range pages {
|
|
pageMap[p.ID] = &AvailableMenuChildResponse{
|
|
Title: p.Name,
|
|
Icon: p.Icon.String,
|
|
To: p.Url.String,
|
|
}
|
|
|
|
if p.ParentId.String != "" {
|
|
pageMap[p.ParentId.String].Children = append(pageMap[p.ParentId.String].Children, pageMap[p.ID])
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|