first commit
This commit is contained in:
		| @@ -0,0 +1,46 @@ | ||||
| package admin_feature | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"znc-server/app/main/api/internal/svc" | ||||
| 	"znc-server/app/main/api/internal/types" | ||||
| 	"znc-server/app/main/model" | ||||
| 	"znc-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 | ||||
| } | ||||
		Reference in New Issue
	
	Block a user