Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gtfsdb/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ FROM
JOIN routes ON trips.route_id = routes.id
JOIN agencies a ON routes.agency_id = a.id
WHERE
stop_times.stop_id IN (sqlc.slice('stop_ids'));
stop_times.stop_id IN (sqlc.slice('stop_ids'))
ORDER BY a.id, stop_times.stop_id;

-- name: GetStopsWithActiveServiceOnDate :many
-- Returns stop IDs that have at least one trip with active service on the given date
Expand Down
1 change: 1 addition & 0 deletions gtfsdb/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions internal/models/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ func NewArrivalsAndDepartureResponse(arrivalsAndDepartures any, references Refer
return NewOKResponse(data, c)
}

func NewArrivalsAndDeparturesForLocationResponse(
arrivalsAndDepartures []ArrivalAndDeparture,
references ReferencesModel,
nearbyStopIds []StopWithDistance,
situationIds []string,
stopIds []string,
limitExceeded bool,
c clock.Clock,
) ResponseModel {
if nearbyStopIds == nil {
nearbyStopIds = []StopWithDistance{}
}
if situationIds == nil {
situationIds = []string{}
}
if stopIds == nil {
stopIds = []string{}
}
entryData := map[string]interface{}{
"arrivalsAndDepartures": arrivalsAndDepartures,
"limitExceeded": limitExceeded,
"nearbyStopIds": nearbyStopIds,
"situationIds": situationIds,
"stopIds": stopIds,
}
data := map[string]interface{}{
"entry": entryData,
"references": references,
}
return NewOKResponse(data, c)
}

// NewResponse creates a standard response using the provided clock.
func NewResponse(code int, data any, text string, c clock.Clock) ResponseModel {
return ResponseModel{
Expand Down
8 changes: 8 additions & 0 deletions internal/models/stops.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ type StopsResponse struct {
List []Stop `json:"list"`
OutOfRange bool `json:"outOfRange"`
}

// StopWithDistance represents a nearby stop together with its distance from the
// centre of the query bounds. It matches the Java StopWithDistanceV2Bean and is
// used by the arrivals-and-departures-for-location endpoint.
type StopWithDistance struct {
StopID string `json:"stopId"`
DistanceFromQuery float64 `json:"distanceFromQuery"`
}
6 changes: 3 additions & 3 deletions internal/restapi/arrivals_and_departure_for_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (api *RestAPI) arrivalsAndDeparturesForStopHandler(w http.ResponseWriter, r

if vehicle != nil {
// Use route.AgencyID instead of stopAgencyID for BuildTripStatus
status, statusErr := api.BuildTripStatus(ctx, route.AgencyID, st.TripID, nil, serviceMidnight, params.Time)
status, statusErr := api.BuildTripStatus(ctx, route.AgencyID, st.TripID, vehicle, serviceMidnight, params.Time)
if statusErr != nil {
api.Logger.Warn("BuildTripStatus failed for arrival",
"tripID", st.TripID, "error", statusErr)
Expand Down Expand Up @@ -427,7 +427,7 @@ func (api *RestAPI) arrivalsAndDeparturesForStopHandler(w http.ResponseWriter, r
continue
}

situationIDs = append(situationIDs, utils.FormCombinedID(route.AgencyID, alert.ID))
situationIDs = append(situationIDs, alert.ID)
if _, seen := collectedAlerts[alert.ID]; !seen {
collectedAlerts[alert.ID] = alert
}
Expand Down Expand Up @@ -628,7 +628,7 @@ func (api *RestAPI) arrivalsAndDeparturesForStopHandler(w http.ResponseWriter, r

topLevelSituationIDSet := make(map[string]struct{}, len(collectedAlerts))
for alertID := range collectedAlerts {
topLevelSituationIDSet[utils.FormCombinedID(alertAgencyID, alertID)] = struct{}{}
topLevelSituationIDSet[alertID] = struct{}{}
}
topLevelSituationIDs := make([]string, 0, len(topLevelSituationIDSet))
for id := range topLevelSituationIDSet {
Expand Down
Loading
Loading