feat(role): Update RoleMenuResponse to use Parent field and preload parent menus in repository
Deploy Application / deploy (push) Successful in 21s Details

This commit is contained in:
Habib Fatkhul Rohman 2025-11-07 14:08:44 +07:00
parent 62082a7dce
commit 81de780ff0
3 changed files with 19 additions and 7 deletions

View File

@ -103,12 +103,12 @@ type RoleResponse struct {
}
type RoleMenuResponse struct {
ID string `json:"id"`
Name string `json:"name"`
IconUrl string `json:"icon_url"`
Url string `json:"url"`
Sequence int `json:"sequence"`
ParentID string `json:"parent_id,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
IconUrl string `json:"icon_url"`
Url string `json:"url"`
Sequence int `json:"sequence"`
Parent *RoleMenuResponse `json:"parent,omitempty"`
}
type RolePermissionsResponse struct {

View File

@ -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
}

View File

@ -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,
})
}