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 2018/12/05 23:20:57 UTC

[GitHub] rawlinp commented on a change in pull request #3081: Fixes missing deliveryservice data fields from the servers/deliveryservices endpoint.

rawlinp commented on a change in pull request #3081: Fixes missing deliveryservice data fields from the servers/deliveryservices endpoint.
URL: https://github.com/apache/trafficcontrol/pull/3081#discussion_r239266381
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go
 ##########
 @@ -472,106 +473,85 @@ func dssSelectQuery() string {
 
 type TODSSDeliveryService struct {
 	ReqInfo *api.APIInfo `json:"-"`
-	tc.DSSDeliveryService
+	tc.DeliveryServiceNullable
 }
 
 func (dss *TODSSDeliveryService) APIInfo() *api.APIInfo {
 	return dss.ReqInfo
 }
 
 func TypeSingleton(reqInfo *api.APIInfo) api.Reader {
-	return &TODSSDeliveryService{reqInfo, tc.DSSDeliveryService{}}
+	return &TODSSDeliveryService{reqInfo, tc.DeliveryServiceNullable{}}
 }
 
 // Read shows all of the delivery services associated with the specified server.
 func (dss *TODSSDeliveryService) Read() ([]interface{}, error, error, int) {
-	orderby := dss.APIInfo().Params["orderby"]
-	if orderby == "" {
-		orderby = "deliveryService"
+	returnable := []interface{}{}
+	params := make(map[string]string)
+	tx := dss.APIInfo().Tx.Tx
+	user := dss.APIInfo().User
+
+	if _, ok := params["orderby"]; !ok {
+		params["orderby"] = "xml_id"
+	}
+
+	// Query Parameters to Database Query column mappings
+	// see the fields mapped in the SQL query
+	queryParamsToSQLCols := map[string]dbhelpers.WhereColumnInfo{
+		"xml_id": dbhelpers.WhereColumnInfo{"ds.xml_id", nil},
+		"xmlId":  dbhelpers.WhereColumnInfo{"ds.xml_id", nil},
+	}
+	where, orderBy, queryValues, errs := dbhelpers.BuildWhereAndOrderBy(params, queryParamsToSQLCols)
+	if len(errs) > 0 {
+		for _, err := range errs {
+			if err.Error() == `id cannot parse to integer` { // TODO create const for string
+				return nil, errors.New("Resource not found."), nil, http.StatusNotFound //matches perl response
+			}
+		}
+		return nil, nil, errors.New("reading dses: " + util.JoinErrsStr(errs)), http.StatusInternalServerError
 	}
 
-	query := SDSSelectQuery()
-	log.Debugln("Query is ", query)
-
-	rows, err := dss.APIInfo().Tx.Queryx(query, dss.APIInfo().Params["id"])
+	tenancyEnabled, err := tenant.IsTenancyEnabledTx(tx)
 
 Review comment:
   I believe we no longer have to do this check as we now have tenancy enabled no matter what, so you can just add the tenancy check unconditionally.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services