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



##########
File path: traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go
##########
@@ -0,0 +1,144 @@
+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 (
+       "net/http"
+       "strconv"
+       "time"
+
+       "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"
+       validation "github.com/go-ozzo/ozzo-validation"
+)
+
+type TOServiceCategory struct {
+       api.APIInfoImpl `json:"-"`
+       tc.ServiceCategory
+}
+
+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 != "" {
+               return serviceCategory.Name
+       }
+       if serviceCategory.ID != 0 {
+               return strconv.Itoa(serviceCategory.ID)
+       }
+       if serviceCategory.TenantID != 0 {
+               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 == 0 {
+               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) ParamColumns() 
map[string]dbhelpers.WhereColumnInfo {
+       return map[string]dbhelpers.WhereColumnInfo{
+               "id":       dbhelpers.WhereColumnInfo{"sc.id", api.IsInt},
+               "name":     dbhelpers.WhereColumnInfo{"sc.name", nil},
+               "tenantId": dbhelpers.WhereColumnInfo{"sc.tenant_id", 
api.IsInt},
+               "tenantName": dbhelpers.WhereColumnInfo{"sc.tenant", nil},
+       }
+}
+
+func (serviceCategory *TOServiceCategory) SelectMaxLastUpdatedQuery(where, 
orderBy, pagination, tableName string) string {
+       return `SELECT max(t) from (
+               SELECT max(last_updated) as t from ` + tableName + ` sc ` + 
where + orderBy + pagination +
+               ` UNION ALL
+       select max(last_updated) as t from last_deleted l where l.table_name='` 
+ tableName + `') as res`
+}
+
+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)
+}
+
+func (serviceCategory *TOServiceCategory) Read(h http.Header, useIMS bool) 
([]interface{}, error, error, int, *time.Time) {
+       return api.GenericRead(h, serviceCategory, useIMS)

Review comment:
       looks like we lost the tenancy check when we used GenericRead




----------------------------------------------------------------
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:
[email protected]


Reply via email to