Skip to content

Commit 093fafd

Browse files
authored
stop REST endpoint: expose filtering by location_type (#576)
1 parent 053098f commit 093fafd

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

doc/openapi/rest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10780,6 +10780,20 @@
1078010780
}
1078110781
]
1078210782
},
10783+
{
10784+
"description": "Filter by location_type: 0=stop/platform, 1=station, 2=entrance/exit, 3=generic node, 4=boarding area",
10785+
"in": "query",
10786+
"name": "location_type",
10787+
"schema": {
10788+
"type": "integer"
10789+
},
10790+
"x-example-requests": [
10791+
{
10792+
"description": "location_type=1",
10793+
"url": "location_type=1"
10794+
}
10795+
]
10796+
},
1078310797
{
1078410798
"$ref": "#/components/parameters/includeAlertsParam"
1078510799
},

server/rest/stop_request.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type StopRequest struct {
3131
ServedByOnestopIds string `json:"served_by_onestop_ids"`
3232
ServedByRouteType *int `json:"served_by_route_type,string"`
3333
ServedByRouteTypes string `json:"served_by_route_types"`
34+
LocationType *int `json:"location_type,string"`
3435
IncludeAlerts bool `json:"include_alerts,string"`
3536
IncludeRoutes bool `json:"include_routes,string"`
3637
LicenseFilter
@@ -86,6 +87,13 @@ func (r StopRequest) RequestInfo() RequestInfo {
8687
Schema: newSRVal("string", "", nil),
8788
Extensions: newExt("", "served_by_route_types=1,2", "served_by_route_types=1,2"),
8889
}},
90+
&pref{Value: &param{
91+
Name: "location_type",
92+
In: "query",
93+
Description: `Filter by location_type: 0=stop/platform, 1=station, 2=entrance/exit, 3=generic node, 4=boarding area`,
94+
Schema: newSRVal("integer", "", nil),
95+
Extensions: newExt("", "location_type=1", "location_type=1"),
96+
}},
8997
newPRef("includeAlertsParam"),
9098
newPRef("includeRoutesParam"),
9199
newPRef("idParam"),
@@ -167,6 +175,9 @@ func (r StopRequest) Query(ctx context.Context) (string, map[string]any) {
167175
if r.ServedByRouteTypes != "" {
168176
where["served_by_route_types"] = commaSplit(r.ServedByRouteTypes)
169177
}
178+
if r.LocationType != nil {
179+
where["location_type"] = *r.LocationType
180+
}
170181
where["license"] = checkLicenseFilter(r.LicenseFilter)
171182
return stopQuery, hw{
172183
"limit": r.CheckLimit(),

server/rest/stop_request_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ func TestStopRequest(t *testing.T) {
157157
selector: "stops.#.stop_id",
158158
expectSelect: []string{"19TH", "19TH_N"},
159159
},
160+
{
161+
name: "location_type=0",
162+
h: StopRequest{FeedOnestopID: "BA", LocationType: ptr(0), WithCursor: WithCursor{Limit: 100}},
163+
selector: "stops.#.stop_id",
164+
expectLength: 50,
165+
},
166+
{
167+
name: "location_type=1",
168+
h: StopRequest{FeedOnestopID: "BA", LocationType: ptr(1), WithCursor: WithCursor{Limit: 100}},
169+
selector: "stops.#.stop_id",
170+
expectLength: 0,
171+
},
160172
{
161173
name: "search",
162174
h: StopRequest{Search: "macarthur"},

0 commit comments

Comments
 (0)