56 lines
1.2 KiB
Go
56 lines
1.2 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 UpdateMenuLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
|
|
return &UpdateMenuLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *UpdateMenuLogic) UpdateMenu(in *pb.UpdateMenuReq) (*pb.Empty, 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())
|
|
}
|
|
|
|
menu.ParentId = in.ParentId
|
|
menu.MenuName = in.MenuName
|
|
menu.MenuType = in.MenuType
|
|
menu.Path = in.Path
|
|
menu.Component = in.Component
|
|
menu.Permission = in.Permission
|
|
menu.Icon = in.Icon
|
|
menu.SortOrder = in.SortOrder
|
|
menu.Visible = in.Visible
|
|
|
|
err = l.svcCtx.MenuModel.Update(l.ctx, menu)
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return &pb.Empty{}, nil
|
|
}
|