55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
|
||
|
|
"muyu-apiserver/model"
|
||
|
|
"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 GetMenuLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewGetMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuLogic {
|
||
|
|
return &GetMenuLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *GetMenuLogic) GetMenu(in *pb.GetMenuReq) (*pb.MenuInfo, error) {
|
||
|
|
menu, err := l.svcCtx.MenuModel.FindOneByMenuId(l.ctx, in.MenuId)
|
||
|
|
if err != nil {
|
||
|
|
if errors.Is(err, model.ErrNotFound) {
|
||
|
|
return nil, status.Error(codes.NotFound, "menu not found")
|
||
|
|
}
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
return &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"),
|
||
|
|
}, nil
|
||
|
|
}
|