elsloo closed pull request #2354: Add TO Go phys_locations/trimmed
URL: https://github.com/apache/incubator-trafficcontrol/pull/2354
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/go-tc/physlocations.go b/lib/go-tc/physlocations.go
index 6d957eeec..c0c32ee3f 100644
--- a/lib/go-tc/physlocations.go
+++ b/lib/go-tc/physlocations.go
@@ -60,3 +60,7 @@ type PhysLocationNullable struct {
        State       *string    `json:"state" db:"state"`
        Zip         *string    `json:"zip" db:"zip"`
 }
+
+type PhysLocationTrimmed struct {
+       Name string `json:"name"`
+}
diff --git a/traffic_ops/traffic_ops_golang/physlocation/trimmed.go 
b/traffic_ops/traffic_ops_golang/physlocation/trimmed.go
new file mode 100644
index 000000000..15f293e3c
--- /dev/null
+++ b/traffic_ops/traffic_ops_golang/physlocation/trimmed.go
@@ -0,0 +1,51 @@
+package physlocation
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+       "database/sql"
+       "errors"
+       "net/http"
+
+       "github.com/apache/incubator-trafficcontrol/lib/go-tc"
+       
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+)
+
+func GetTrimmed(db *sql.DB) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               api.RespWriter(w, r)(getTrimmed(db))
+       }
+}
+
+func getTrimmed(db *sql.DB) ([]tc.PhysLocationTrimmed, error) {
+       rows, err := db.Query(`SELECT name FROM phys_location`)
+       if err != nil {
+               return nil, errors.New("querying trimmed physical locations: " 
+ err.Error())
+       }
+       ps := []tc.PhysLocationTrimmed{}
+       for rows.Next() {
+               name := ""
+               if err = rows.Scan(&name); err != nil {
+                       return nil, errors.New("scanning trimmed physical 
locations: " + err.Error())
+               }
+               ps = append(ps, tc.PhysLocationTrimmed{Name: name})
+       }
+       return ps, nil
+}
diff --git a/traffic_ops/traffic_ops_golang/routes.go 
b/traffic_ops/traffic_ops_golang/routes.go
index 693bc62db..61a270d5e 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -139,6 +139,7 @@ func Routes(d ServerData) ([]Route, []RawRoute, 
http.Handler, error) {
 
                //Phys_Location: CRUD
                {1.1, http.MethodGet, `phys_locations/?(\.json)?$`, 
api.ReadHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
+               {1.1, http.MethodGet, `phys_locations/trimmed/?(\.json)?$`, 
physlocation.GetTrimmed(d.DB.DB), auth.PrivLevelReadOnly, Authenticated, nil},
                {1.1, http.MethodGet, `phys_locations/{id}$`, 
api.ReadHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelReadOnly, 
Authenticated, nil},
                {1.1, http.MethodPut, `phys_locations/{id}$`, 
api.UpdateHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelOperations, 
Authenticated, nil},
                {1.1, http.MethodPost, `phys_locations/?$`, 
api.CreateHandler(physlocation.GetRefType(), d.DB), auth.PrivLevelOperations, 
Authenticated, nil},


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to