d4x1 commented on code in PR #6146:
URL: 
https://github.com/apache/incubator-devlake/pull/6146#discussion_r1338172539


##########
backend/helpers/utils/mapstructure.go:
##########
@@ -38,6 +38,17 @@ func DecodeHook(f reflect.Type, t reflect.Type, data 
interface{}) (interface{},
        if t == reflect.TypeOf(json.RawMessage{}) {
                return json.Marshal(data)
        }
+       // to support decodng url.Values (quer string) to non-array variables

Review Comment:
   typo `decodng` `quer`.



##########
backend/helpers/pluginhelper/api/connection_auths.go:
##########
@@ -144,6 +144,11 @@ func (ma *MultiAuth) 
SetupAuthenticationForConnection(connection plugin.ApiConne
        return apiAuthenticator.SetupAuthentication(req)
 }
 
+func (ma *MultiAuth) CustomValidate(connection interface{}, v 
*validator.Validate) errors.Error {
+       return ma.ValidateConnection(connection, v)
+}
+
+// TODO: deprecated, rename to CustomValidate instead

Review Comment:
   Comment with "Deprecated, xxx" will be parsed by golang tool chain.  It's 
better for us to follow this.



##########
backend/helpers/pluginhelper/api/ds_connection_api_helper.go:
##########
@@ -0,0 +1,76 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "strconv"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+// DsConnectionApiHelper
+type DsConnectionApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig] struct {

Review Comment:
   C stands fro `Connection`, S stands for `Scope`, SC stands for ScopeConfig, 
the letter C in SC means `Config`.
   It's confusing when I see it the first time.
   



##########
backend/helpers/pluginhelper/api/ds_connection_api_helper.go:
##########
@@ -0,0 +1,76 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "strconv"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+// DsConnectionApiHelper
+type DsConnectionApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig] struct {
+       *ModelApiHelper[C]
+       *srvhelper.ConnectionSrvHelper[C, S, SC]
+}
+
+func NewDsConnectionApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig](
+       basicRes context.BasicRes,
+       connSrvHelper *srvhelper.ConnectionSrvHelper[C, S, SC],
+) *DsConnectionApiHelper[C, S, SC] {
+       return &DsConnectionApiHelper[C, S, SC]{
+               ModelApiHelper:      NewModelApiHelper[C](basicRes, 
connSrvHelper.ModelSrvHelper, []string{"connectionId"}),
+               ConnectionSrvHelper: connSrvHelper,
+       }
+}
+
+func (connApi *DsConnectionApiHelper[C, S, SC]) Delete(input 
*plugin.ApiResourceInput) (out *plugin.ApiResourceOutput, err errors.Error) {
+       var conn *C
+       conn, err = connApi.FindByPk(input)
+       if err != nil {
+               return nil, err
+       }
+       refs, err := connApi.ConnectionSrvHelper.DeleteConnection(conn)
+       if err != nil {
+               return &plugin.ApiResourceOutput{Body: &shared.ApiBody{
+                       Success: false,
+                       Message: err.Error(),
+                       Data:    refs,
+               }, Status: err.GetType().GetHttpCode()}, nil
+       }
+       return &plugin.ApiResourceOutput{
+               Body: conn,
+       }, nil
+}
+
+// DsScopeApiHelper

Review Comment:
   comment doesn't match the code.



##########
backend/helpers/pluginhelper/api/ds_connection_api_helper.go:
##########
@@ -0,0 +1,76 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "strconv"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+// DsConnectionApiHelper

Review Comment:
   what does `Ds` mean? 



##########
backend/helpers/pluginhelper/api/ds_helper.go:
##########
@@ -0,0 +1,49 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+)
+
+func NewDataSourceHelpers[

Review Comment:
   So `NewDataSourceHelpers ` will return five helpers. 
   Does the caller need five helpers at the same time? If yes, why not wrap 
them into one struct; if no, why return five helpers?



##########
backend/helpers/pluginhelper/api/model_api_helper.go:
##########
@@ -0,0 +1,160 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "fmt"
+       "net/http"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/helpers/utils"
+)
+
+type ModelApiHelper[M dal.Tabler] struct {
+       basicRes       context.BasicRes
+       dalHelper      *srvhelper.ModelSrvHelper[M]
+       log            log.Logger
+       modelName      string
+       pkPathVarNames []string
+}
+
+func NewModelApiHelper[M dal.Tabler](
+       basicRes context.BasicRes,
+       dalHelper *srvhelper.ModelSrvHelper[M],
+       pkPathVarNames []string, // path variable names of primary key
+) *ModelApiHelper[M] {
+       m := new(M)
+       modelName := fmt.Sprintf("%T", m)
+       return &ModelApiHelper[M]{
+               basicRes:       basicRes,
+               dalHelper:      dalHelper,
+               log:            
basicRes.GetLogger().Nested(fmt.Sprintf("%s_dal", modelName)),
+               modelName:      modelName,
+               pkPathVarNames: pkPathVarNames,
+       }
+}
+
+func (self *ModelApiHelper[M]) Post(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       model := new(M)
+       err := utils.DecodeMapStruct(input.Body, model, false)
+       if err != nil {
+               return nil, err
+       }
+       err = self.dalHelper.Create(model)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Status: http.StatusCreated,
+               Body:   model,
+       }, nil
+}
+
+func (self *ModelApiHelper[M]) FindByPk(input *plugin.ApiResourceInput) (*M, 
errors.Error) {
+       pkv := make([]interface{}, len(self.pkPathVarNames))
+       for i, pkn := range self.pkPathVarNames {
+               pkv[i] = input.Params[pkn]
+       }
+       return self.dalHelper.FindByPk(pkv...)
+}
+
+func (self *ModelApiHelper[M]) GetDetail(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       model, err := self.FindByPk(input)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Body: model,
+       }, nil
+}
+
+func (self *ModelApiHelper[M]) Patch(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       model, err := self.FindByPk(input)
+       if err != nil {
+               return nil, err
+       }
+       err = utils.DecodeMapStruct(input.Body, model, true)
+       if err != nil {
+               return nil, errors.BadInput.Wrap(err, fmt.Sprintf("faled to 
patch %s", self.modelName))
+       }
+       err = self.dalHelper.Update(model)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Body: model,
+       }, nil
+}
+
+func (self *ModelApiHelper[M]) Delete(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       model, err := self.FindByPk(input)
+       if err != nil {
+               return nil, err
+       }
+       err = self.dalHelper.DeleteModel(model)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Body: model,
+       }, nil
+}
+
+func (self *ModelApiHelper[M]) GetAll(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       all, err := self.dalHelper.GetAll()
+       return &plugin.ApiResourceOutput{
+               Body: all,
+       }, err
+}
+
+func (self *ModelApiHelper[M]) PutMultiple(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput, errors.Error) {
+       var req struct {
+               Data []M `json:"data"`
+       }
+       err := utils.DecodeMapStruct(input.Body, &req, false)
+       if err != nil {
+               return nil, err
+       }
+       for i, item := range req.Data {
+               err := self.dalHelper.CreateOrUpdate(&item)
+               if err != nil {
+                       return nil, errors.BadInput.Wrap(err, 
fmt.Sprintf("failed to save item %d", i))
+               }
+       }
+       return &plugin.ApiResourceOutput{
+               Body: req.Data,
+       }, nil
+}
+
+func ParsePagination[P any](input *plugin.ApiResourceInput, query 
...dal.Clause) (*P, errors.Error) {

Review Comment:
   1. It should be unexported if it is in this package.
   2.It's not a part of  xxx_helper(beacuse helpers need to be used by 
`NewXXX`),  I think it jus  a uitl function.



##########
backend/helpers/pluginhelper/api/ds_scope_api_helper.go:
##########
@@ -0,0 +1,99 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+type DsScopeApiHelper[C plugin.ToolLayerConnection, S plugin.ToolLayerScope, 
SC plugin.ToolLayerScopeConfig] struct {
+       *ModelApiHelper[S]
+       *srvhelper.ScopeSrvHelper[C, S, SC]
+}
+
+func NewDsScopeApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig](
+       basicRes context.BasicRes,
+       srvHelper *srvhelper.ScopeSrvHelper[C, S, SC],
+) *DsScopeApiHelper[C, S, SC] {
+       return &DsScopeApiHelper[C, S, SC]{
+               ModelApiHelper: NewModelApiHelper[S](basicRes, 
srvHelper.ModelSrvHelper, []string{"connectionId", "scopeId"}),
+               ScopeSrvHelper: srvHelper,
+       }
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) GetPage(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       pagination, err := ParsePagination[srvhelper.ScopePagination](input)
+       if err != nil {
+               return nil, errors.BadInput.Wrap(err, "failed to decode 
pathvars into pagination")
+       }
+       scopes, count, err := connApi.ScopeSrvHelper.GetScopesPage(pagination)
+       if err != nil {

Review Comment:
   if something goes wrong here, a log will be helpful. Please consider adding 
some logs when an error occured, especially in this situation, the error just 
be passed to the caller without any addtional infomation.



##########
backend/helpers/pluginhelper/api/ds_scope_api_helper.go:
##########
@@ -0,0 +1,99 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+type DsScopeApiHelper[C plugin.ToolLayerConnection, S plugin.ToolLayerScope, 
SC plugin.ToolLayerScopeConfig] struct {
+       *ModelApiHelper[S]
+       *srvhelper.ScopeSrvHelper[C, S, SC]
+}
+
+func NewDsScopeApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig](
+       basicRes context.BasicRes,
+       srvHelper *srvhelper.ScopeSrvHelper[C, S, SC],
+) *DsScopeApiHelper[C, S, SC] {
+       return &DsScopeApiHelper[C, S, SC]{
+               ModelApiHelper: NewModelApiHelper[S](basicRes, 
srvHelper.ModelSrvHelper, []string{"connectionId", "scopeId"}),
+               ScopeSrvHelper: srvHelper,
+       }
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) GetPage(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       pagination, err := ParsePagination[srvhelper.ScopePagination](input)
+       if err != nil {
+               return nil, errors.BadInput.Wrap(err, "failed to decode 
pathvars into pagination")
+       }
+       scopes, count, err := connApi.ScopeSrvHelper.GetScopesPage(pagination)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Body: map[string]interface{}{
+                       "count":  count,
+                       "scopes": scopes,
+               },
+       }, nil
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) PutMultiple(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       // fix data[].connectionId

Review Comment:
   Maybe this comment should be placed in function extractConnectionId.



##########
backend/helpers/srvhelper/dsrefs.go:
##########
@@ -0,0 +1,46 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/models"
+)
+
+type DsRefs struct {
+       Blueprints []string `json:"blueprints"`
+       Projects   []string `json:"projects"`
+}
+
+func toDsRefs(blueprints []*models.Blueprint) (*DsRefs, errors.Error) {
+       if len(blueprints) > 0 {
+               blueprintNames := make([]string, 0, len(blueprints))
+               projectNames := make([]string, 0, len(blueprints))
+               for _, bp := range blueprints {
+                       blueprintNames = append(blueprintNames, bp.Name)
+                       if bp.ProjectName != "" {
+                               projectNames = append(projectNames, 
bp.ProjectName)
+                       }
+               }
+               return &DsRefs{
+                       Blueprints: blueprintNames,
+                       Projects:   projectNames,
+               }, errors.Conflict.New("Cannot delete record because it is 
referenced by blueprints")

Review Comment:
   1. From the error message, we cannot get infomation like: which record is 
referened by which blueprint.
   2. This function seems to convert  blueprints to something else,  there is 
no logical about `delete record`.
   
   Please consider to update the error message, or the funtion's name.   



##########
backend/helpers/pluginhelper/api/ds_scope_api_helper.go:
##########
@@ -0,0 +1,99 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/server/api/shared"
+)
+
+type DsScopeApiHelper[C plugin.ToolLayerConnection, S plugin.ToolLayerScope, 
SC plugin.ToolLayerScopeConfig] struct {
+       *ModelApiHelper[S]
+       *srvhelper.ScopeSrvHelper[C, S, SC]
+}
+
+func NewDsScopeApiHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig](
+       basicRes context.BasicRes,
+       srvHelper *srvhelper.ScopeSrvHelper[C, S, SC],
+) *DsScopeApiHelper[C, S, SC] {
+       return &DsScopeApiHelper[C, S, SC]{
+               ModelApiHelper: NewModelApiHelper[S](basicRes, 
srvHelper.ModelSrvHelper, []string{"connectionId", "scopeId"}),
+               ScopeSrvHelper: srvHelper,
+       }
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) GetPage(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       pagination, err := ParsePagination[srvhelper.ScopePagination](input)
+       if err != nil {
+               return nil, errors.BadInput.Wrap(err, "failed to decode 
pathvars into pagination")
+       }
+       scopes, count, err := connApi.ScopeSrvHelper.GetScopesPage(pagination)
+       if err != nil {
+               return nil, err
+       }
+       return &plugin.ApiResourceOutput{
+               Body: map[string]interface{}{
+                       "count":  count,
+                       "scopes": scopes,
+               },
+       }, nil
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) PutMultiple(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       // fix data[].connectionId
+       connectionId, err := extractConnectionId(input)
+       if err != nil {
+               return nil, err
+       }
+       data, ok := input.Body["data"].([]interface{})
+       if !ok {
+               return nil, errors.BadInput.New("invalid data")
+       }
+       for _, row := range data {
+               dict, ok := row.(map[string]interface{})
+               if !ok {
+                       return nil, errors.BadInput.New("invalid data row")
+               }
+               dict["connectionId"] = connectionId
+       }
+       return connApi.ModelApiHelper.PutMultiple(input)
+}
+
+func (connApi *DsScopeApiHelper[C, S, SC]) Delete(input 
*plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
+       var scope *S
+       scope, err := connApi.FindByPk(input)
+       if err != nil {
+               return nil, err
+       }
+       // time.Sleep(1 * time.Minute) # uncomment this line if you were to 
verify pipelines get blocked while deleting data
+       // check referencing blueprints
+       refs, err := connApi.ScopeSrvHelper.DeleteScope(scope, 
input.Query.Get("delete_data_only") == "true")

Review Comment:
   Is `delete_data_only `  a magic variable?



##########
backend/helpers/pluginhelper/api/model_api_helper.go:
##########
@@ -0,0 +1,160 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+       "fmt"
+       "net/http"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/srvhelper"
+       "github.com/apache/incubator-devlake/helpers/utils"
+)
+
+type ModelApiHelper[M dal.Tabler] struct {
+       basicRes       context.BasicRes
+       dalHelper      *srvhelper.ModelSrvHelper[M]
+       log            log.Logger
+       modelName      string
+       pkPathVarNames []string
+}
+
+func NewModelApiHelper[M dal.Tabler](
+       basicRes context.BasicRes,
+       dalHelper *srvhelper.ModelSrvHelper[M],
+       pkPathVarNames []string, // path variable names of primary key

Review Comment:
   1. Does variables' order matter?
   2. `primary key` should be  plural form `primary keys`.



##########
backend/helpers/srvhelper/connection_service_helper.go:
##########
@@ -0,0 +1,82 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/core/plugin"
+)
+
+// ConnectionSrvHelper
+type ConnectionSrvHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig] struct {
+       *ModelSrvHelper[C]
+       pluginName string
+}
+
+// NewConnectionSrvHelper creates a ConnectionDalHelper for connection 
management
+func NewConnectionSrvHelper[
+       C plugin.ToolLayerConnection,
+       S plugin.ToolLayerScope,
+       SC plugin.ToolLayerScopeConfig,
+](
+       basicRes context.BasicRes,
+       pluginName string,
+) *ConnectionSrvHelper[C, S, SC] {
+       return &ConnectionSrvHelper[C, S, SC]{
+               ModelSrvHelper: NewModelSrvHelper[C](basicRes),
+               pluginName:     pluginName,
+       }
+}
+
+func (connSrv *ConnectionSrvHelper[C, S, SC]) DeleteConnection(connection *C) 
(refs *DsRefs, err errors.Error) {
+       err = connSrv.ModelSrvHelper.NoRunningPipeline(func(tx dal.Transaction) 
errors.Error {
+               // make sure no blueprint is using the connection
+               connectionId := (*connection).ConnectionId()
+               refs, err = 
toDsRefs(connSrv.getAllBlueprinsByConnection(connectionId))
+               if err != nil {
+                       return err
+               }
+               scopeCount := errors.Must1(connSrv.db.Count(dal.From(new(S)), 
dal.Where("connection_id = ?", connectionId)))

Review Comment:
   I saw many codes use `errors.Must1` or `errors.Must`, which means if 
something goes wrong, the program will panic.  Is it as expected?



##########
backend/helpers/srvhelper/model_service_helper.go:
##########
@@ -0,0 +1,215 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "fmt"
+       "time"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/helpers/dbhelper"
+       "github.com/go-playground/validator/v10"
+)
+
+type CustomValidator interface {
+       CustomValidate(entitiy interface{}, validate *validator.Validate) 
errors.Error
+}
+
+type ModelSrvHelper[M dal.Tabler] struct {
+       basicRes      context.BasicRes
+       log           log.Logger
+       db            dal.Dal
+       validator     *validator.Validate
+       modelName     string
+       pk            []dal.ColumnMeta
+       pkWhere       string
+       pkCount       int
+       searchColumns []string
+}
+
+func NewModelSrvHelper[M dal.Tabler](basicRes context.BasicRes) 
*ModelSrvHelper[M] {
+       m := new(M)
+       modelName := fmt.Sprintf("%T", m)
+       db := basicRes.GetDal()
+       if db == nil {
+               db = basicRes.GetDal()
+       }
+       pk := errors.Must1(dal.GetPrimarykeyColumns(db, *m))
+       pkWhere := ""
+       for _, col := range pk {
+               if pkWhere != "" {
+                       pkWhere += " AND "
+               }
+               pkWhere += fmt.Sprintf("%s = ? ", col.Name())
+       }
+       return &ModelSrvHelper[M]{
+               basicRes:  basicRes,
+               log:       basicRes.GetLogger().Nested(fmt.Sprintf("%s_dal", 
modelName)),
+               db:        db,
+               validator: validator.New(),
+               modelName: modelName,
+               pk:        pk,
+               pkWhere:   pkWhere,
+               pkCount:   len(pk),
+       }
+}
+
+func (srv *ModelSrvHelper[M]) NewTx(tx dal.Transaction) *ModelSrvHelper[M] {
+       helper := new(ModelSrvHelper[M])
+       *helper = *srv
+       helper.db = tx
+       return helper
+}
+
+func (srv *ModelSrvHelper[M]) ValidateModel(model *M) errors.Error {
+       // the model can validate itself
+       if customValidator, ok := (interface{}(model)).(CustomValidator); ok {
+               return customValidator.CustomValidate(model, srv.validator)
+       }
+       // basic validator
+       if e := srv.validator.Struct(model); e != nil {
+               return errors.BadInput.Wrap(e, "validation faild")
+       }
+       return nil
+}
+
+// Create validates given model and insert it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Create(model *M) errors.Error {
+       println("create model")
+       err := srv.ValidateModel(model)
+       if err != nil {
+               return err
+       }
+       err = srv.db.Create(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {
+                       return errors.Conflict.Wrap(err, fmt.Sprintf("%s 
already exists", srv.modelName))
+               }
+               return err
+       }
+       return err
+}
+
+// Update validates given model and update it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Update(model *M) errors.Error {
+       err := srv.ValidateModel(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {

Review Comment:
   Can update return db's duplicated error?



##########
backend/helpers/srvhelper/model_service_helper.go:
##########
@@ -0,0 +1,215 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "fmt"
+       "time"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/helpers/dbhelper"
+       "github.com/go-playground/validator/v10"
+)
+
+type CustomValidator interface {
+       CustomValidate(entitiy interface{}, validate *validator.Validate) 
errors.Error

Review Comment:
   1. typo `entitiy`.
   2. Param entitiy is unnecessary, because  a struct who implement 
`CustomValidator` will hold itself and can validate itself.
   3. Param validate is unnecessary too, a struct who implement 
`CustomValidator` can validate without any validator.
   4. please consider renaming `CustomValidator` to `Validate`.



##########
backend/helpers/srvhelper/scope_config_service_helper.go:
##########
@@ -0,0 +1,66 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+)
+
+// ScopeConfigSrvHelper
+type ScopeConfigSrvHelper[C plugin.ToolLayerConnection, S 
plugin.ToolLayerScope, SC plugin.ToolLayerScopeConfig] struct {
+       *ModelSrvHelper[SC]
+}
+
+func NewScopeConfigSrvHelper[
+       C plugin.ToolLayerConnection,
+       S plugin.ToolLayerScope,
+       SC plugin.ToolLayerScopeConfig,
+](basicRes context.BasicRes) *ScopeConfigSrvHelper[C, S, SC] {
+       return &ScopeConfigSrvHelper[C, S, SC]{
+               ModelSrvHelper: NewModelSrvHelper[SC](basicRes),
+       }
+}
+
+func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) 
GetAllByConnectionId(connectionId uint64) ([]*SC, errors.Error) {
+       var scopeConfigs []*SC
+       err := scopeConfigSrv.db.All(&scopeConfigs,
+               dal.Where("connection_id = ?", connectionId),
+               dal.Orderby("id DESC"),
+       )
+       return scopeConfigs, err
+}
+
+func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) 
DeleteScopeConfig(scopeConfig *SC) (refs []*S, err errors.Error) {
+       err = scopeConfigSrv.ModelSrvHelper.NoRunningPipeline(func(tx 
dal.Transaction) errors.Error {
+               // make sure no scope is using the scopeConfig
+               sc := (*scopeConfig)

Review Comment:
   `sc := (*scopeConfig)`, why parentheses? 



##########
backend/helpers/srvhelper/model_service_helper.go:
##########
@@ -0,0 +1,215 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "fmt"
+       "time"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/helpers/dbhelper"
+       "github.com/go-playground/validator/v10"
+)
+
+type CustomValidator interface {
+       CustomValidate(entitiy interface{}, validate *validator.Validate) 
errors.Error
+}
+
+type ModelSrvHelper[M dal.Tabler] struct {
+       basicRes      context.BasicRes
+       log           log.Logger
+       db            dal.Dal
+       validator     *validator.Validate
+       modelName     string
+       pk            []dal.ColumnMeta
+       pkWhere       string
+       pkCount       int
+       searchColumns []string
+}
+
+func NewModelSrvHelper[M dal.Tabler](basicRes context.BasicRes) 
*ModelSrvHelper[M] {
+       m := new(M)
+       modelName := fmt.Sprintf("%T", m)
+       db := basicRes.GetDal()
+       if db == nil {
+               db = basicRes.GetDal()
+       }
+       pk := errors.Must1(dal.GetPrimarykeyColumns(db, *m))
+       pkWhere := ""
+       for _, col := range pk {
+               if pkWhere != "" {
+                       pkWhere += " AND "
+               }
+               pkWhere += fmt.Sprintf("%s = ? ", col.Name())
+       }
+       return &ModelSrvHelper[M]{
+               basicRes:  basicRes,
+               log:       basicRes.GetLogger().Nested(fmt.Sprintf("%s_dal", 
modelName)),
+               db:        db,
+               validator: validator.New(),
+               modelName: modelName,
+               pk:        pk,
+               pkWhere:   pkWhere,
+               pkCount:   len(pk),
+       }
+}
+
+func (srv *ModelSrvHelper[M]) NewTx(tx dal.Transaction) *ModelSrvHelper[M] {
+       helper := new(ModelSrvHelper[M])
+       *helper = *srv
+       helper.db = tx
+       return helper
+}
+
+func (srv *ModelSrvHelper[M]) ValidateModel(model *M) errors.Error {
+       // the model can validate itself
+       if customValidator, ok := (interface{}(model)).(CustomValidator); ok {
+               return customValidator.CustomValidate(model, srv.validator)
+       }
+       // basic validator
+       if e := srv.validator.Struct(model); e != nil {
+               return errors.BadInput.Wrap(e, "validation faild")
+       }
+       return nil
+}
+
+// Create validates given model and insert it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Create(model *M) errors.Error {
+       println("create model")
+       err := srv.ValidateModel(model)
+       if err != nil {
+               return err
+       }
+       err = srv.db.Create(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {
+                       return errors.Conflict.Wrap(err, fmt.Sprintf("%s 
already exists", srv.modelName))
+               }
+               return err
+       }
+       return err
+}
+
+// Update validates given model and update it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Update(model *M) errors.Error {
+       err := srv.ValidateModel(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {
+                       return errors.Conflict.Wrap(err, fmt.Sprintf("%s 
already exists", srv.modelName))
+               }
+               return err
+       }
+       return srv.db.Update(model)
+}
+
+// CreateOrUpdate validates given model and insert or update it into database 
if validation passed
+func (srv *ModelSrvHelper[M]) CreateOrUpdate(model *M) errors.Error {
+       err := srv.ValidateModel(model)
+       if err != nil {
+               return err
+       }
+       return srv.db.CreateOrUpdate(model)
+}
+
+// DeleteModel deletes given model from database
+func (srv *ModelSrvHelper[M]) DeleteModel(model *M) errors.Error {
+       return srv.db.Delete(model)
+}
+
+// FindByPk returns model with given primary key from database
+func (srv *ModelSrvHelper[M]) FindByPk(pk ...interface{}) (*M, errors.Error) {
+       if len(pk) != srv.pkCount {
+               return nil, errors.BadInput.New("invalid primary key")
+       }
+       model := new(M)
+       err := srv.db.First(model, dal.Where(srv.pkWhere, pk...))
+       if err != nil {
+               if srv.db.IsErrorNotFound(err) {
+                       return nil, errors.NotFound.Wrap(err, fmt.Sprintf("%s 
not found", srv.modelName))
+               }
+               return nil, err
+       }
+       return model, nil
+}
+
+// GetAll returns all models from database
+func (srv *ModelSrvHelper[M]) GetAll() ([]*M, errors.Error) {
+       array := make([]*M, 0)

Review Comment:
   `var array []*M` is preffered.
   



##########
backend/helpers/srvhelper/model_service_helper.go:
##########
@@ -0,0 +1,215 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package srvhelper
+
+import (
+       "fmt"
+       "time"
+
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/log"
+       "github.com/apache/incubator-devlake/core/models"
+       "github.com/apache/incubator-devlake/helpers/dbhelper"
+       "github.com/go-playground/validator/v10"
+)
+
+type CustomValidator interface {
+       CustomValidate(entitiy interface{}, validate *validator.Validate) 
errors.Error
+}
+
+type ModelSrvHelper[M dal.Tabler] struct {
+       basicRes      context.BasicRes
+       log           log.Logger
+       db            dal.Dal
+       validator     *validator.Validate
+       modelName     string
+       pk            []dal.ColumnMeta
+       pkWhere       string
+       pkCount       int
+       searchColumns []string
+}
+
+func NewModelSrvHelper[M dal.Tabler](basicRes context.BasicRes) 
*ModelSrvHelper[M] {
+       m := new(M)
+       modelName := fmt.Sprintf("%T", m)
+       db := basicRes.GetDal()
+       if db == nil {
+               db = basicRes.GetDal()
+       }
+       pk := errors.Must1(dal.GetPrimarykeyColumns(db, *m))
+       pkWhere := ""
+       for _, col := range pk {
+               if pkWhere != "" {
+                       pkWhere += " AND "
+               }
+               pkWhere += fmt.Sprintf("%s = ? ", col.Name())
+       }
+       return &ModelSrvHelper[M]{
+               basicRes:  basicRes,
+               log:       basicRes.GetLogger().Nested(fmt.Sprintf("%s_dal", 
modelName)),
+               db:        db,
+               validator: validator.New(),
+               modelName: modelName,
+               pk:        pk,
+               pkWhere:   pkWhere,
+               pkCount:   len(pk),
+       }
+}
+
+func (srv *ModelSrvHelper[M]) NewTx(tx dal.Transaction) *ModelSrvHelper[M] {
+       helper := new(ModelSrvHelper[M])
+       *helper = *srv
+       helper.db = tx
+       return helper
+}
+
+func (srv *ModelSrvHelper[M]) ValidateModel(model *M) errors.Error {
+       // the model can validate itself
+       if customValidator, ok := (interface{}(model)).(CustomValidator); ok {
+               return customValidator.CustomValidate(model, srv.validator)
+       }
+       // basic validator
+       if e := srv.validator.Struct(model); e != nil {
+               return errors.BadInput.Wrap(e, "validation faild")
+       }
+       return nil
+}
+
+// Create validates given model and insert it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Create(model *M) errors.Error {
+       println("create model")
+       err := srv.ValidateModel(model)
+       if err != nil {
+               return err
+       }
+       err = srv.db.Create(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {
+                       return errors.Conflict.Wrap(err, fmt.Sprintf("%s 
already exists", srv.modelName))
+               }
+               return err
+       }
+       return err
+}
+
+// Update validates given model and update it into database if validation 
passed
+func (srv *ModelSrvHelper[M]) Update(model *M) errors.Error {
+       err := srv.ValidateModel(model)
+       if err != nil {
+               if srv.db.IsDuplicationError(err) {
+                       return errors.Conflict.Wrap(err, fmt.Sprintf("%s 
already exists", srv.modelName))
+               }
+               return err
+       }
+       return srv.db.Update(model)
+}
+
+// CreateOrUpdate validates given model and insert or update it into database 
if validation passed
+func (srv *ModelSrvHelper[M]) CreateOrUpdate(model *M) errors.Error {
+       err := srv.ValidateModel(model)
+       if err != nil {
+               return err
+       }
+       return srv.db.CreateOrUpdate(model)
+}
+
+// DeleteModel deletes given model from database
+func (srv *ModelSrvHelper[M]) DeleteModel(model *M) errors.Error {
+       return srv.db.Delete(model)
+}
+
+// FindByPk returns model with given primary key from database
+func (srv *ModelSrvHelper[M]) FindByPk(pk ...interface{}) (*M, errors.Error) {
+       if len(pk) != srv.pkCount {
+               return nil, errors.BadInput.New("invalid primary key")
+       }
+       model := new(M)
+       err := srv.db.First(model, dal.Where(srv.pkWhere, pk...))
+       if err != nil {
+               if srv.db.IsErrorNotFound(err) {
+                       return nil, errors.NotFound.Wrap(err, fmt.Sprintf("%s 
not found", srv.modelName))
+               }
+               return nil, err
+       }
+       return model, nil
+}
+
+// GetAll returns all models from database
+func (srv *ModelSrvHelper[M]) GetAll() ([]*M, errors.Error) {
+       array := make([]*M, 0)
+       return array, srv.db.All(&array)
+}
+
+func (srv *ModelSrvHelper[M]) GetPage(pagination *Pagination, query 
...dal.Clause) ([]*M, int64, errors.Error) {
+       query = append(query, dal.From(new(M)))
+       // process keyword
+       searchTerm := pagination.SearchTerm
+       if searchTerm != "" && len(srv.searchColumns) > 0 {

Review Comment:
   This will cause sql injection by splicing sql mauanlly, especiall searchterm 
is from client side.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to