rob05c commented on a change in pull request #3900: Rewrite 
/cachegroups/{{id}}/parameters to Go
URL: https://github.com/apache/trafficcontrol/pull/3900#discussion_r321002073
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/cachegroup/parameters.go
 ##########
 @@ -0,0 +1,111 @@
+package cachegroup
+
+/*
+ * 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.
+ */
+
+import (
+       "errors"
+       "net/http"
+       "strconv"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/lib/go-util"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/parameter"
+)
+
+const (
+       CacheGroupIDQueryParam = "id"
+       ParameterIDQueryParam  = "parameterId"
+)
+
+//we need a type alias to define functions on
+type TOCacheGroupParameter struct {
+       api.APIInfoImpl `json:"-"`
+       tc.CacheGroupParameterNullable
+}
+
+func (cgparam *TOCacheGroupParameter) ParamColumns() 
map[string]dbhelpers.WhereColumnInfo {
+       return map[string]dbhelpers.WhereColumnInfo{
+               CacheGroupIDQueryParam: 
dbhelpers.WhereColumnInfo{"cgp.cachegroup", api.IsInt},
+               ParameterIDQueryParam:  dbhelpers.WhereColumnInfo{"p.id", 
api.IsInt},
+       }
+}
+
+func (cgparam *TOCacheGroupParameter) GetType() string {
+       return "cachegroup_params"
+}
+
+func (cgparam *TOCacheGroupParameter) Read() ([]interface{}, error, error, 
int) {
+       queryParamsToQueryCols := cgparam.ParamColumns()
+       parameters := cgparam.APIInfo().Params
+       where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(parameters, queryParamsToQueryCols)
+       if len(errs) > 0 {
+               return nil, util.JoinErrs(errs), nil, http.StatusBadRequest
+       }
+
+       cgID, err := strconv.Atoi(parameters[CacheGroupIDQueryParam])
+       if err != nil {
+               return nil, nil, errors.New("cache group id must be an 
integer"), http.StatusInternalServerError
+       }
+
+       _, ok, err := getCGNameFromID(cgparam.ReqInfo.Tx.Tx, int64(cgID))
+       if err != nil {
+               return nil, nil, errors.New("getting cachegroup from id"), 
http.StatusInternalServerError
 
 Review comment:
   It also needs to include the error context, so it's easier to debug when it 
happens: ```
   return nil, nil, errors.New("getting cachegroup from id: " + err.Error()), 
http.StatusInternalServerError
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to