muyu-apiserver/rpc/system/internal/logic/updaterolelogic.go

51 lines
1.1 KiB
Go
Raw Normal View History

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 UpdateRoleLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleLogic {
return &UpdateRoleLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateRoleLogic) UpdateRole(in *pb.UpdateRoleReq) (*pb.Empty, error) {
role, err := l.svcCtx.RoleModel.FindOneByRoleId(l.ctx, in.RoleId)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
return nil, status.Error(codes.NotFound, "role not found")
}
return nil, status.Error(codes.Internal, err.Error())
}
role.RoleName = in.RoleName
role.RoleKey = in.RoleKey
role.RoleDesc = in.RoleDesc
role.SortOrder = in.SortOrder
err = l.svcCtx.RoleModel.Update(l.ctx, role)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &pb.Empty{}, nil
}