|
|
|
@@ -27,11 +27,14 @@ func NewCreateAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre |
|
|
|
|
|
|
|
func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *types.AdapterResp, err error) { |
|
|
|
adapter := types.AdapterInfo{} |
|
|
|
existAdapter := types.AdapterResp{} |
|
|
|
resp = &types.AdapterResp{} |
|
|
|
utils.Convert(req, &adapter) |
|
|
|
//check name |
|
|
|
exist := l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&types.AdapterInfo{}).Error |
|
|
|
exist := l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&existAdapter).Error |
|
|
|
if !errors.Is(exist, gorm.ErrRecordNotFound) { |
|
|
|
return nil, errors.New("name already exists") |
|
|
|
resp = &existAdapter |
|
|
|
return resp, errors.New("name already exists") |
|
|
|
} |
|
|
|
//check type |
|
|
|
var arr = [...]string{"0", "1", "2"} |
|
|
|
@@ -60,8 +63,10 @@ func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *t |
|
|
|
adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05") |
|
|
|
result := l.svcCtx.DbEngin.Table("t_adapter").Create(&adapter) |
|
|
|
if result.Error != nil { |
|
|
|
return nil, result.Error |
|
|
|
return resp, result.Error |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
_ = l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&existAdapter).Error |
|
|
|
resp = &existAdapter |
|
|
|
return resp, nil |
|
|
|
} |