shamrickus commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1276587912


##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@
  */
 
 import (
+       "database/sql"
+       "encoding/json"
+       "errors"
        "fmt"
        "net/http"
        "strconv"
        "strings"
        "time"
 
+       "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/dbhelpers"
+       
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
 
        "github.com/asaskevich/govalidator"
        validation "github.com/go-ozzo/ozzo-validation"
 )
 
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
 type TOCDN struct {
        api.APIInfoImpl `json:"-"`
        tc.CDNNullable
 }
 
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
-       return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+       var runSecond bool
+       var maxTime time.Time
+       inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+       tx := inf.Tx
+       if userErr != nil || sysErr != nil {
+               api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+               return
+       }
+       defer inf.Close()
+
+       // Query Parameters to Database Query column mappings
+       queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+               "domainName":    dbhelpers.WhereColumnInfo{Column: 
"domain_name"},
+               "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: 
"dnssec_enabled"},
+               "id":            dbhelpers.WhereColumnInfo{Column: "id", 
Checker: api.IsInt},
+               "name":          dbhelpers.WhereColumnInfo{Column: "name"},
+               "ttlOverride":   dbhelpers.WhereColumnInfo{Column: 
"ttl_override", Checker: api.IsInt},
+       }
+
+       if _, ok := inf.Params["orderby"]; !ok {
+               inf.Params["orderby"] = "name"
+       }
+       where, orderBy, pagination, queryValues, errs := 
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+       if len(errs) > 0 {
+               api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, 
util.JoinErrs(errs), nil)
+               return
+       }
+
+       if inf.Config.UseIMS {
+               runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, 
queryValues, SelectMaxLastUpdatedQuery(where))
+               if !runSecond {
+                       log.Debugln("IMS HIT")
+                       api.AddLastModifiedHdr(w, maxTime)
+                       w.WriteHeader(http.StatusNotModified)
+                       return
+               }
+               log.Debugln("IMS MISS")
+       } else {
+               log.Debugln("Non IMS request")
+       }
+
+       query := selectQuery(inf.Version) + where + orderBy + pagination
+       rows, err := tx.NamedQuery(query, queryValues)

Review Comment:
   Pretty sure this is properly handled, if not then this is a problem with 
most of our endpoints.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to