feat(role): Update RoleMenuResponse to use Parent field and preload parent menus in repository
Deploy Application / deploy (push) Successful in 21s
Details
Deploy Application / deploy (push) Successful in 21s
Details
This commit is contained in:
parent
62082a7dce
commit
81de780ff0
|
|
@ -108,7 +108,7 @@ type RoleMenuResponse struct {
|
||||||
IconUrl string `json:"icon_url"`
|
IconUrl string `json:"icon_url"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Sequence int `json:"sequence"`
|
Sequence int `json:"sequence"`
|
||||||
ParentID string `json:"parent_id,omitempty"`
|
Parent *RoleMenuResponse `json:"parent,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RolePermissionsResponse struct {
|
type RolePermissionsResponse struct {
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,7 @@ func (r *roleRepository) GetRoleByID(ctx context.Context, tx *gorm.DB, id string
|
||||||
Preload("Client").
|
Preload("Client").
|
||||||
Preload("Permissions").
|
Preload("Permissions").
|
||||||
Preload("Menus").
|
Preload("Menus").
|
||||||
|
Preload("Menus.Parent").
|
||||||
First(&role).Error; err != nil {
|
First(&role).Error; err != nil {
|
||||||
return entities.M_Role{}, err
|
return entities.M_Role{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -497,13 +497,24 @@ func ToRoleResponse(role entities.M_Role) dto.RoleResponse {
|
||||||
|
|
||||||
var menus []dto.RoleMenuResponse
|
var menus []dto.RoleMenuResponse
|
||||||
for _, m := range role.Menus {
|
for _, m := range role.Menus {
|
||||||
|
var parent *dto.RoleMenuResponse
|
||||||
|
if m.Parent != nil {
|
||||||
|
parent = &dto.RoleMenuResponse{
|
||||||
|
ID: m.Parent.ID.String(),
|
||||||
|
Name: m.Parent.Name,
|
||||||
|
IconUrl: m.Parent.IconUrl,
|
||||||
|
Url: m.Parent.Url,
|
||||||
|
Sequence: m.Parent.Sequence,
|
||||||
|
Parent: nil, // atau rekursif jika ingin nested lebih dalam
|
||||||
|
}
|
||||||
|
}
|
||||||
menus = append(menus, dto.RoleMenuResponse{
|
menus = append(menus, dto.RoleMenuResponse{
|
||||||
ID: m.ID.String(),
|
ID: m.ID.String(),
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
IconUrl: m.IconUrl,
|
IconUrl: m.IconUrl,
|
||||||
Url: m.Url,
|
Url: m.Url,
|
||||||
Sequence: m.Sequence,
|
Sequence: m.Sequence,
|
||||||
ParentID: m.ParentID.String(),
|
Parent: parent,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue