You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2020/07/17 15:42:40 UTC

[GitHub] [trafficcontrol] jehunte commented on a change in pull request #4518: Add service category feature to TO and TP

jehunte commented on a change in pull request #4518:
URL: https://github.com/apache/trafficcontrol/pull/4518#discussion_r456522774



##########
File path: traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
##########
@@ -0,0 +1,199 @@
+package servicecategory
+
+/*
+ * 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 (
+	"fmt"
+	"github.com/jmoiron/sqlx"
+	"net/http"
+	"strconv"
+
+	"github.com/apache/trafficcontrol/lib/go-log"
+	"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/auth"
+	"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"
+)
+
+//we need a type alias to define functions on
+type TOServiceCategory struct {
+	api.APIInfoImpl `json:"-"`
+	tc.ServiceCategoryNullable
+}
+
+func (v *TOServiceCategory) SetLastUpdated(t tc.TimeNoMod) { v.LastUpdated = &t }
+func (v *TOServiceCategory) InsertQuery() string           { return insertQuery() }
+func (v *TOServiceCategory) NewReadObj() interface{}       { return &tc.ServiceCategory{} }
+func (v *TOServiceCategory) SelectQuery() string           { return selectQuery() }
+func (v *TOServiceCategory) UpdateQuery() string           { return updateQuery() }
+func (v *TOServiceCategory) DeleteQuery() string           { return deleteQuery() }
+
+func (serviceCategory TOServiceCategory) GetAuditName() string {
+	if serviceCategory.Name != nil {
+		return *serviceCategory.Name
+	}
+	if serviceCategory.ID != nil {
+		return strconv.Itoa(*serviceCategory.ID)
+	}
+	if serviceCategory.TenantID != nil {
+		return strconv.Itoa(*serviceCategory.TenantID)
+	}
+	return "unknown"
+}
+
+func (serviceCategory TOServiceCategory) GetKeyFieldsInfo() []api.KeyFieldInfo {
+	return []api.KeyFieldInfo{{"id", api.GetIntKey}}
+}
+
+//Implementation of the Identifier, Validator interface functions
+func (serviceCategory TOServiceCategory) GetKeys() (map[string]interface{}, bool) {
+	if serviceCategory.ID == nil {
+		return map[string]interface{}{"id": 0}, false
+	}
+	return map[string]interface{}{"id": *serviceCategory.ID}, true
+}
+
+func (serviceCategory *TOServiceCategory) SetKeys(keys map[string]interface{}) {
+	i, _ := keys["id"].(int) //this utilizes the non panicking type assertion, if the thrown away ok variable is false i will be the zero of the type, 0 here.
+	serviceCategory.ID = &i
+}
+
+func (serviceCategory TOServiceCategory) GetType() string {
+	return "serviceCategory"
+}
+
+func (serviceCategory TOServiceCategory) Validate() error {
+	errs := validation.Errors{
+		"name":     validation.Validate(serviceCategory.Name, validation.NotNil, validation.Required),
+		"tenantId": validation.Validate(serviceCategory.TenantID, validation.Min(1)),
+	}
+	return util.JoinErrs(tovalidate.ToErrors(errs))
+}
+
+func (serviceCategory *TOServiceCategory) Create() (error, error, int) {
+	return api.GenericCreate(serviceCategory)

Review comment:
       This would require a large architecture change and I believe is out of scope for this feature. 




----------------------------------------------------------------
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:
users@infra.apache.org