jagan-parthiban commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237037418
##########
lib/go-tc/asns.go:
##########
@@ -99,3 +120,29 @@ type ASNNullable struct {
type ASNsV11 struct {
ASNs []interface{} `json:"asns"`
}
+
+// ASNsV5 is used for RFC3339 format timestamp
+type ASNV5 struct {
Review Comment:
Same as Above
type ASNV5 = ASNV50
##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
Alerts
}
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {
Review Comment:
As per convention across all others structs, we have a specific version that
does not changes, and then an alias for the most recent version.
So in this case, we'd want to have a ASNsResponseV50 that looks like what
you have here, and then a type named ASNsResponseV5 that is just an alias of
that like
type ASNsResponseV5 = ASNsResponseV50
##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
Alerts
}
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {
+ // in: body
+ Response []ASNV5 `json:"response"`
+ Alerts
+}
+
+// ASNResponseV5 is a single ASN response for Update and Create to depict what
+// changed.
+// swagger:response ASNResponse
+// in: body
+type ASNResponseV5 struct {
Review Comment:
Same as Above
type ASNResponseV5 = ASNResponseV50
##########
traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go:
##########
@@ -2202,3 +2202,18 @@ func ServiceCategoryExists(tx *sql.Tx, name string)
(bool, error) {
}
return true, nil
}
+
+// GetASNInfo confirms whether the asn exists, and an error (if one occurs).
+func GetASNInfo(tx *sql.Tx, id string) (bool, error) {
Review Comment:
As this function does not get the ASNInfo and it only confirms the existence
of the ASN, should we rename the funcion to something like `ASNExists`
##########
traffic_ops/traffic_ops_golang/asn/asns.go:
##########
@@ -204,3 +209,229 @@ RETURNING
func deleteQuery() string {
return `DELETE FROM asn WHERE id=:id`
}
+
+// Read gets list of ASNs for APIv5
+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{
+ "asn": {Column: "a.asn", Checker: api.IsInt},
+ "id": {Column: "a.id", Checker: api.IsInt},
+ }
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "asn"
+ }
+ 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)
+ }
+
+ 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() + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
+ if err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil,
fmt.Errorf("asn read: error getting asn(s): %w", err))
+ }
+ defer log.Close(rows, "unable to close DB connection")
+
+ asn := tc.ASNV5{}
+ asnList := []tc.ASNV5{}
Review Comment:
Should we change the empty slice declaration Semantics to `var asnList
[]tc.ASNV5`
##########
lib/go-tc/asns.go:
##########
@@ -1,5 +1,7 @@
package tc
+import "time"
Review Comment:
For Uniformity across all files, Import statement can be below the Licence
text.
--
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]