Skip to content

Commit 929a0b6

Browse files
Merge pull request #112 from OneBusAway/trips-for-route
Feat: Add Trips for Route EndPoint
2 parents 7e1215e + f9ab230 commit 929a0b6

11 files changed

+841
-257
lines changed

gtfsdb/db.go

Lines changed: 46 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gtfsdb/query.sql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,13 @@ SELECT
595595
r.long_name as route_long_name
596596
FROM
597597
stop_times st
598-
JOIN trips t ON st.trip_id = t.id
599-
JOIN routes r ON t.route_id = r.id
598+
JOIN trips t ON st.trip_id = t.id
599+
JOIN routes r ON t.route_id = r.id
600600
WHERE
601601
st.stop_id = ?
602602
ORDER BY
603-
st.arrival_time LIMIT 50
603+
st.arrival_time LIMIT 50;
604+
-- name: GetTripsByServiceID :many
605+
SELECT *
606+
FROM trips
607+
WHERE service_id IN (sqlc.slice('service_ids'));

gtfsdb/query.sql.go

Lines changed: 128 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/models/trip.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ func NewTripReference(id, routeID, serviceID, headSign, shortName string, direct
3939
TripShortName: shortName,
4040
}
4141
}
42+
43+
type TripsSchedule struct {
44+
Frequency *int64 `json:"frequency"`
45+
NextTripId string `json:"nextTripId"`
46+
PreviousTripId string `json:"previousTripId"`
47+
StopTimes []StopTime `json:"stopTimes"`
48+
TimeZone string `json:"timeZone"`
49+
}

internal/models/trips_for_location.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@ type TripsForLocationData struct {
1212
}
1313

1414
type TripsForLocationListEntry struct {
15-
Frequency *int64 `json:"frequency"`
16-
Schedule *TripsForLocationSchedule `json:"schedule,omitempty"`
17-
ServiceDate int64 `json:"serviceDate"`
18-
SituationIds []string `json:"situationIds"`
19-
TripId string `json:"tripId"`
15+
Frequency *int64 `json:"frequency"`
16+
Schedule *TripsSchedule `json:"schedule,omitempty"`
17+
ServiceDate int64 `json:"serviceDate"`
18+
SituationIds []string `json:"situationIds"`
19+
TripId string `json:"tripId"`
2020
}
2121

22-
type TripsForLocationSchedule struct {
23-
Frequency *int64 `json:"frequency"`
24-
NextTripId string `json:"nextTripId"`
25-
PreviousTripId string `json:"previousTripId"`
26-
StopTimes []StopTime `json:"stopTimes"`
27-
TimeZone string `json:"timeZone"`
28-
}
22+
func (e TripsForLocationListEntry) GetTripId() string { return e.TripId }

internal/models/trips_for_route.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package models
2+
3+
type TripsForRouteResponse struct {
4+
Code int64 `json:"code"`
5+
CurrentTime int64 `json:"currentTime"`
6+
Data TripsForRouteData `json:"data"`
7+
}
8+
9+
type TripsForRouteData struct {
10+
LimitExceeded bool `json:"limitExceeded"`
11+
List []TripsForRouteListEntry `json:"list"`
12+
}
13+
14+
type TripsForRouteListEntry struct {
15+
Frequency *int64 `json:"frequency"`
16+
Schedule *TripsSchedule `json:"schedule,omitempty"`
17+
Status *TripStatusForTripDetails `json:"status,omitempty"`
18+
ServiceDate int64 `json:"serviceDate"`
19+
SituationIds []string `json:"situationIds"`
20+
TripId string `json:"tripId"`
21+
}
22+
23+
func (e TripsForRouteListEntry) GetTripId() string { return e.TripId }

internal/restapi/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (api *RestAPI) SetRoutes(mux *http.ServeMux) {
7171
mux.Handle("GET /api/where/trip-for-vehicle/{id}", rateLimitAndValidateAPIKey(api, api.tripForVehicleHandler))
7272
mux.Handle("GET /api/where/trips-for-location.json", rateLimitAndValidateAPIKey(api, api.tripsForLocationHandler))
7373
mux.Handle("GET /api/where/arrival-and-departure-for-stop/{id}", rateLimitAndValidateAPIKey(api, api.arrivalAndDepartureForStopHandler))
74+
mux.Handle("GET /api/where/trips-for-route/{id}", rateLimitAndValidateAPIKey(api, api.tripsForRouteHandler))
7475
}
7576

7677
// SetupAPIRoutes creates and configures the API router with all middleware applied globally

0 commit comments

Comments
 (0)