47 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package admin_feature
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 
 | |
| 	"hm-server/app/main/api/internal/svc"
 | |
| 	"hm-server/app/main/api/internal/types"
 | |
| 	"hm-server/app/main/model"
 | |
| 	"hm-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
 | |
| }
 |