70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package menu
|
|
|
|
import (
|
|
"context"
|
|
|
|
"muyu-apiserver/gateway/internal/svc"
|
|
"muyu-apiserver/gateway/internal/types"
|
|
"muyu-apiserver/pkg/ctxdata"
|
|
"muyu-apiserver/rpc/system/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetMenuLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuLogic {
|
|
return &GetMenuLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetMenuLogic) GetMenu() (resp *types.MenuInfo, err error) {
|
|
id := ctxdata.GetPathId(l.ctx)
|
|
|
|
rpcResp, err := l.svcCtx.SystemRpc.GetMenu(l.ctx, &pb.GetMenuReq{
|
|
MenuId: id,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return convertMenuInfo(rpcResp), nil
|
|
}
|
|
|
|
func convertMenuInfo(m *pb.MenuInfo) *types.MenuInfo {
|
|
if m == nil {
|
|
return nil
|
|
}
|
|
|
|
children := make([]types.MenuInfo, 0, len(m.Children))
|
|
for _, c := range m.Children {
|
|
if c != nil {
|
|
children = append(children, *convertMenuInfo(c))
|
|
}
|
|
}
|
|
|
|
return &types.MenuInfo{
|
|
MenuId: m.MenuId,
|
|
ParentId: m.ParentId,
|
|
MenuName: m.MenuName,
|
|
MenuType: m.MenuType,
|
|
Path: m.Path,
|
|
Component: m.Component,
|
|
Permission: m.Permission,
|
|
Icon: m.Icon,
|
|
SortOrder: m.SortOrder,
|
|
Visible: m.Visible,
|
|
Status: m.Status,
|
|
Children: children,
|
|
CreatedAt: m.CreatedAt,
|
|
UpdatedAt: m.UpdatedAt,
|
|
}
|
|
}
|