rimashah25 commented on code in PR #7561: URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237151106
########## 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: not necessary. There are two ways to initiate and define a variable. -- 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: issues-unsubscr...@trafficcontrol.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org