Skip to content

fix: populate situations in vehicles-for-agency references#819

Open
reddy-santhu wants to merge 1 commit intoOneBusAway:mainfrom
reddy-santhu:fix/vehicles-for-agency-situations
Open

fix: populate situations in vehicles-for-agency references#819
reddy-santhu wants to merge 1 commit intoOneBusAway:mainfrom
reddy-santhu:fix/vehicles-for-agency-situations

Conversation

@reddy-santhu
Copy link
Copy Markdown
Contributor

closes #818

fixes the vehicles-for-agency endpoint always returning an empty
references.situations array. Checked the Java OBA server (MTA NYCT
production) and it does return situations in the references block for this
endpoint.

The handler was simply never wired up to collect alerts. Every other endpoint
that returns a references block already does this.

Changes

internal/restapi/vehicles_for_agency_handler.go

After building the vehicle list, collect route-level and agency-wide alerts
and populate references.situations. Route IDs are already gathered before
the loop for the existing batch route fetch, so nothing new hits the DB.

alerts := deduplicateAlerts(
    api.collectAlertsForRoutes(routeIDs),
    api.GtfsManager.GetAlertsByIDs("", "", id),
)
references.Situations = append(references.Situations, api.BuildSituationReferences(alerts)...)

internal/gtfs/gtfs_manager_mock.go

MockResetRealTimeData wasn't clearing feedAlerts, so any test that
injected an alert into the shared manager would leak it into later tests.
Added the missing reset and a rebuildMergedRealtimeLocked call.

Testing

Added two tests:

  • route-scoped alert shows up in references.situations
  • agency-wide alert shows up in references.situations

Trip-scoped alerts are intentionally not collected here doing so would
require a DB query per vehicle which doesn't scale over a full fleet. Route
and agency scoping covers what real feeds publish in practice, and matches
how other endpoints handle the same trade-off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vehicles-for-agency: references.situations is always empty

1 participant