41 lines
962 B
Go
41 lines
962 B
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 SetRolePermissionsLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewSetRolePermissionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetRolePermissionsLogic {
|
||
|
|
return &SetRolePermissionsLogic{
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *SetRolePermissionsLogic) SetRolePermissions(in *pb.SetRolePermissionsReq) (*pb.Empty, error) {
|
||
|
|
err := l.svcCtx.RoleMenuModel.DeleteByRoleId(l.ctx, in.RoleId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
err = l.svcCtx.RoleMenuModel.BatchInsert(l.ctx, in.RoleId, in.MenuIds)
|
||
|
|
if err != nil {
|
||
|
|
return nil, status.Error(codes.Internal, err.Error())
|
||
|
|
}
|
||
|
|
|
||
|
|
return &pb.Empty{}, nil
|
||
|
|
}
|