zrhoffman commented on a change in pull request #5094:
URL: https://github.com/apache/trafficcontrol/pull/5094#discussion_r499314091



##########
File path: traffic_ops/traffic_ops_golang/deliveryservice/deliveryservices.go
##########
@@ -266,6 +266,14 @@ func createV30(w http.ResponseWriter, r *http.Request, inf 
*api.APIInfo, ds tc.D
                deepCachingType = ds.DeepCachingType.String() // necessary, 
because DeepCachingType's default needs to insert the string, not "", and Query 
doesn't call .String().
        }
 
+       if ds.Topology != nil {
+               if ok, err := dbhelpers.TopologyExistsString(tx, *ds.Topology); 
err != nil {
+                       return nil, http.StatusInternalServerError, nil, 
fmt.Errorf("checking topology existence: %v", err)
+               } else if !ok {
+                       return nil, http.StatusConflict, fmt.Errorf("no such 
Topology '%s'", *ds.Topology), nil

Review comment:
       409 Status Conflict doesn't really fit here since the error does not 
necessarily stem from an issue relating to state.

##########
File path: traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
##########
@@ -812,6 +812,14 @@ func GetCacheGroupNameFromID(tx *sql.Tx, id int) 
(tc.CacheGroupName, bool, error
        return tc.CacheGroupName(name), true, nil
 }
 
+// TopologyExistsString is a convenience function for checking if a Topology 
exists
+// when its name is an actual string instead of a 
github.com/apache/trafficcontrol/lib/go-tc.TopologyName
+func TopologyExistsString(tx *sql.Tx, name string) (bool, error) {
+       return TopologyExists(tx, tc.TopologyName(name))
+}

Review comment:
       I would rather `TopologyExists()` take a string than add an additional 
`TopologyExistsString()`. `TopologyExists()` was only used 1 place before this 
PR, so adding a typecast to `string` in the calling function should be pretty 
easy




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