feat(dto): Add Permissions field to MenuResponse and update related services
Deploy Application / deploy (push) Successful in 20s
Details
Deploy Application / deploy (push) Successful in 20s
Details
This commit is contained in:
parent
8fe9a5bb5c
commit
8fe0448aa8
|
|
@ -71,6 +71,7 @@ type (
|
|||
Mode string `json:"mode"`
|
||||
Status string `json:"status"`
|
||||
Parent *MenuParentResponse `json:"parent"`
|
||||
Permissions []dto.PermissionResponse `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
MenuParentResponse struct {
|
||||
|
|
|
|||
|
|
@ -39,17 +39,9 @@ func (f *MenuFilter) ApplyFilters(q *gorm.DB) *gorm.DB {
|
|||
q = q.Where("client_id = ?", f.ClientID)
|
||||
}
|
||||
|
||||
// allow selective preloads for performance
|
||||
for _, include := range f.Includes {
|
||||
if include == "Parent" {
|
||||
// q = q.Model(entities.M_Menu{}).Preload("Parent", func(db *gorm.DB) *gorm.DB {
|
||||
// return db.Select("id", "name")
|
||||
// })
|
||||
q = q.Model(entities.M_Menu{}).Preload("Parent", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("m_menus.id", "m_menus.name")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return q
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,10 @@ func (m *menuRepository) GetById(ctx context.Context, tx *gorm.DB, menuId string
|
|||
|
||||
var menu entities.M_Menu
|
||||
// preload Parent relation jika entitas M_Menu punya association Parent
|
||||
if err := tx.WithContext(ctx).Preload("Parent").First(&menu, "id = ?", menuId).Error; err != nil {
|
||||
if err := tx.WithContext(ctx).
|
||||
Preload("Parent").
|
||||
Preload("Permissions").
|
||||
First(&menu, "id = ?", menuId).Error; err != nil {
|
||||
return entities.M_Menu{}, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/Caknoooo/go-gin-clean-starter/modules/auth/service"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/menu/dto"
|
||||
"github.com/Caknoooo/go-gin-clean-starter/modules/menu/repository"
|
||||
staticDto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
|
@ -121,6 +122,17 @@ func (m *menuService) GetById(ctx context.Context, menuId string) (dto.MenuRespo
|
|||
res.Parent = &dto.MenuParentResponse{ID: entity.ParentID.String()}
|
||||
}
|
||||
|
||||
if len(entity.Permissions) > 0 {
|
||||
res.Permissions = make([]staticDto.PermissionResponse, 0, len(entity.Permissions))
|
||||
for _, perm := range entity.Permissions {
|
||||
res.Permissions = append(res.Permissions, staticDto.PermissionResponse{
|
||||
ID: perm.ID.String(),
|
||||
Name: perm.Name,
|
||||
// Description: perm.Description,
|
||||
// Code: perm.Code,
|
||||
})
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,4 +15,9 @@ type (
|
|||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
PermissionResponse struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in New Issue