46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
|
package admin_feature
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"tyc-server/app/main/api/internal/svc"
|
||
|
"tyc-server/app/main/api/internal/types"
|
||
|
"tyc-server/app/main/model"
|
||
|
"tyc-server/common/xerr"
|
||
|
|
||
|
"github.com/pkg/errors"
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type AdminCreateFeatureLogic struct {
|
||
|
logx.Logger
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
}
|
||
|
|
||
|
func NewAdminCreateFeatureLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminCreateFeatureLogic {
|
||
|
return &AdminCreateFeatureLogic{
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (l *AdminCreateFeatureLogic) AdminCreateFeature(req *types.AdminCreateFeatureReq) (resp *types.AdminCreateFeatureResp, err error) {
|
||
|
// 1. 数据转换
|
||
|
data := &model.Feature{
|
||
|
ApiId: req.ApiId,
|
||
|
Name: req.Name,
|
||
|
}
|
||
|
|
||
|
// 2. 数据库操作
|
||
|
result, err := l.svcCtx.FeatureModel.Insert(l.ctx, nil, data)
|
||
|
if err != nil {
|
||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR),
|
||
|
"创建功能失败, err: %v, req: %+v", err, req)
|
||
|
}
|
||
|
|
||
|
// 3. 返回结果
|
||
|
id, _ := result.LastInsertId()
|
||
|
return &types.AdminCreateFeatureResp{Id: id}, nil
|
||
|
}
|