mhoppa commented on a change in pull request #4026: Feature/add deliveryservice 
required capability
URL: https://github.com/apache/trafficcontrol/pull/4026#discussion_r338793786
 
 

 ##########
 File path: 
traffic_ops/traffic_ops_golang/deliveryservice/deliveryservice_required_capabilities.go
 ##########
 @@ -0,0 +1,293 @@
+package deliveryservice
+
+/*
+ * 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"
+       "fmt"
+       "net/http"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+       "github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+       "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/dbhelpers"
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
+       validation "github.com/go-ozzo/ozzo-validation"
+)
+
+const (
+       deliveryServiceQueryParam    = "deliveryServiceID"
+       requiredCapabilityQueryParam = "requiredCapability"
+       xmlIDQueryParam              = "xmlID"
+)
+
+// RequiredCapability provides a type to define methods on.
+type RequiredCapability struct {
+       api.APIInfoImpl `json:"-"`
+       tc.DeliveryServiceRequiredCapability
+}
+
+// SetLastUpdated implements the api.GenericCreator interfaces and
+// sets the timestamp on insert.
+func (sc *RequiredCapability) SetLastUpdated(t tc.TimeNoMod) { sc.LastUpdated 
= &t }
+
+// NewReadObj implements the api.GenericReader interfaces.
+func (sc *RequiredCapability) NewReadObj() interface{} {
+       return &tc.DeliveryServiceRequiredCapability{}
+}
+
+// SelectQuery implements the api.GenericReader interface.
+func (sc *RequiredCapability) SelectQuery() string {
+       return `SELECT
+       sc.required_capability,
+       sc.deliveryservice_id,
+       ds.xml_id,
+       sc.last_updated
+       FROM deliveryservice_required_capability sc
+       JOIN deliveryservice ds ON ds.id = sc.deliveryservice_id`
+}
+
+// ParamColumns implements the api.GenericReader interface.
+func (sc *RequiredCapability) ParamColumns() 
map[string]dbhelpers.WhereColumnInfo {
+       return map[string]dbhelpers.WhereColumnInfo{
+               deliveryServiceQueryParam: dbhelpers.WhereColumnInfo{
+                       Column:  "sc.deliveryservice_id",
+                       Checker: api.IsInt,
+               },
+               xmlIDQueryParam: dbhelpers.WhereColumnInfo{
+                       Column:  "ds.xml_id",
+                       Checker: nil,
+               },
+               requiredCapabilityQueryParam: dbhelpers.WhereColumnInfo{
+                       Column:  "sc.required_capability",
+                       Checker: nil,
+               },
+       }
+}
+
+// DeleteQuery implements the api.GenericDeleter interface.
+func (sc *RequiredCapability) DeleteQuery() string {
+       return `DELETE FROM deliveryservice_required_capability
+       WHERE deliveryservice_id = :deliveryservice_id AND required_capability 
= :required_capability`
+}
+
+// GetKeyFieldsInfo implements the api.Identifier interface.
+func (sc RequiredCapability) GetKeyFieldsInfo() []api.KeyFieldInfo {
+       return []api.KeyFieldInfo{
+               {
+                       Field: deliveryServiceQueryParam,
+                       Func:  api.GetIntKey,
+               },
+               {
+                       Field: requiredCapabilityQueryParam,
+                       Func:  api.GetStringKey,
+               },
+       }
+}
+
+// GetKeys implements the api.Identifier interface and is not needed
+// because Update is not available.
+func (sc RequiredCapability) GetKeys() (map[string]interface{}, bool) {
+       return nil, false
 
 Review comment:
   this should return something similar to 
https://github.com/apache/trafficcontrol/blob/master/traffic_ops/traffic_ops_golang/server/servers_server_capability.go#L69
 as it is used in the change log logic 

----------------------------------------------------------------
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