47 lines
987 B
Go
47 lines
987 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"muyu-apiserver/model"
|
|
"muyu-apiserver/pkg/uid"
|
|
"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 CreateRoleLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleLogic {
|
|
return &CreateRoleLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *CreateRoleLogic) CreateRole(in *pb.CreateRoleReq) (*pb.IdResp, error) {
|
|
roleId := uid.Generate()
|
|
|
|
_, err := l.svcCtx.RoleModel.Insert(l.ctx, &model.SysRole{
|
|
RoleId: roleId,
|
|
RoleName: in.RoleName,
|
|
RoleKey: in.RoleKey,
|
|
RoleDesc: in.RoleDesc,
|
|
SortOrder: in.SortOrder,
|
|
Status: 1,
|
|
})
|
|
if err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return &pb.IdResp{Id: roleId}, nil
|
|
}
|