diff --git a/CHANGELOG.md b/CHANGELOG.md index 503305553c..f6d1d6eed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#7366](https://github.com/apache/trafficcontrol/pull/7366) *t3c* Removed timestamp from metadata file since it's changing every minute and causing excessive commits to git repo. ### Fixed +- [#7130](https://github.com/apache/trafficcontrol/issues/7130) *Traffic Ops* Fixes service_categories response to POST API. - [#7340](https://github.com/apache/trafficcontrol/pull/7340) *Traffic Router* Fixed TR logging for the `cqhv` field when absent. - [#5557](https://github.com/apache/trafficcontrol/issues/5557) *Traffic Portal* Moved `Fair Queueing Pacing Rate Bps` DS field to `Cache Configuration Settings` section. - [#7252](https://github.com/apache/trafficcontrol/issues/7252) *Traffic Router* Fixed integer overflow for `czCount`, by resetting the count to max value when it overflows. diff --git a/traffic_ops/traffic_ops_golang/api/generic_crud.go b/traffic_ops/traffic_ops_golang/api/generic_crud.go index 2ad292d6d7..f1cf640e78 100644 --- a/traffic_ops/traffic_ops_golang/api/generic_crud.go +++ b/traffic_ops/traffic_ops_golang/api/generic_crud.go @@ -119,19 +119,36 @@ func GenericCreateNameBasedID(val GenericCreator) (error, error, int) { } defer resultRows.Close() + var name string lastUpdated := tc.TimeNoMod{} rowsAffected := 0 + for resultRows.Next() { rowsAffected++ - if err := resultRows.Scan(&lastUpdated); err != nil { + // Only when the type is of serviceCategory, &name is scanned and returned from the DB. + // Else return only &lastUpdated. + var err error + if val.GetType() == "serviceCategory" { + err = resultRows.Scan(&name, &lastUpdated) + } else { + err = resultRows.Scan(&lastUpdated) + } + if err != nil { return nil, errors.New(val.GetType() + " create scanning: " + err.Error()), http.StatusInternalServerError } } + if rowsAffected == 0 { return nil, errors.New(val.GetType() + " create: no " + val.GetType() + " was inserted, no row was returned"), http.StatusInternalServerError } else if rowsAffected > 1 { return nil, errors.New("too many rows returned from " + val.GetType() + " insert"), http.StatusInternalServerError } + + // Only when the type is of serviceCategory, setKeys to return name parameter. + if val.GetType() == "serviceCategory" { + val.SetKeys(map[string]interface{}{"name": name}) + } + val.SetLastUpdated(lastUpdated) return nil, nil, http.StatusOK } diff --git a/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go b/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go index 79e85e1b7d..8201de1fd5 100644 --- a/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go +++ b/traffic_ops/traffic_ops_golang/servicecategory/servicecategories.go @@ -100,7 +100,7 @@ func (serviceCategory TOServiceCategory) Validate() (error, error) { } func (serviceCategory *TOServiceCategory) Create() (error, error, int) { - return api.GenericCreate(serviceCategory) + return api.GenericCreateNameBasedID(serviceCategory) } func (serviceCategory *TOServiceCategory) Read(h http.Header, useIMS bool) ([]interface{}, error, error, int, *time.Time) {