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"`
|
||||
Url string `json:"url"`
|
||||
Sequence int `json:"sequence"`
|
||||
ParentID string `json:"parent_id,omitempty"`
|
||||
Parent *RoleMenuResponse `json:"parent,omitempty"`
|
||||
}
|
||||
|
||||
type RolePermissionsResponse struct {
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ func (r *roleRepository) GetRoleByID(ctx context.Context, tx *gorm.DB, id string
|
|||
Preload("Client").
|
||||
Preload("Permissions").
|
||||
Preload("Menus").
|
||||
Preload("Menus.Parent").
|
||||
First(&role).Error; err != nil {
|
||||
return entities.M_Role{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -497,13 +497,24 @@ func ToRoleResponse(role entities.M_Role) dto.RoleResponse {
|
|||
|
||||
var menus []dto.RoleMenuResponse
|
||||
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{
|
||||
ID: m.ID.String(),
|
||||
Name: m.Name,
|
||||
IconUrl: m.IconUrl,
|
||||
Url: m.Url,
|
||||
Sequence: m.Sequence,
|
||||
ParentID: m.ParentID.String(),
|
||||
Parent: parent,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue