55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/rpc/system/internal/svc"
|
||
|
|
"muyu-apiserver/rpc/system/pb"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
"google.golang.org/grpc/codes"
|
||
|
|
"google.golang.org/grpc/status"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ListMenuLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListMenuLogic {
|
||
|
|
return &ListMenuLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListMenuLogic) ListMenu(in *pb.ListMenuReq) (*pb.ListMenuResp, error) {
|
||
|
|
menus, err := l.svcCtx.MenuModel.FindAll(l.ctx)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
list := make([]*pb.MenuInfo, 0, len(menus))
|
||
|
|
for _, menu := range menus {
|
||
|
|
list = append(list, &pb.MenuInfo{
|
||
|
|
MenuId: menu.MenuId,
|
||
|
|
ParentId: menu.ParentId,
|
||
|
|
MenuName: menu.MenuName,
|
||
|
|
MenuType: menu.MenuType,
|
||
|
|
Path: menu.Path,
|
||
|
|
Component: menu.Component,
|
||
|
|
Permission: menu.Permission,
|
||
|
|
Icon: menu.Icon,
|
||
|
|
SortOrder: menu.SortOrder,
|
||
|
|
Visible: menu.Visible,
|
||
|
|
Status: menu.Status,
|
||
|
|
CreatedAt: menu.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
UpdatedAt: menu.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.ListMenuResp{List: list}, nil
|
||
|
|
}
|