fix: honor time request param in vehicles-for-agency API#1106
Conversation
Parse the 'time' query parameter in the vehicles-for-agency endpoint to set the reference time, falling back to the server clock if absent. This fixes a spec gap where the parameter was silently ignored. Add validation to return HTTP 400 on invalid time formats using the existing ParseTimeParameter utility. Add test coverage for epoch-ms, absent, and invalid inputs.
|
Warning Review limit reached
More reviews will be available in 48 minutes and 7 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe vehicles-for-agency handler now uses an optional ChangesVehicles-for-agency reference time
Estimated review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/restapi/vehicles_for_agency_handler.go`:
- Around line 32-47: The request handler currently calls loadAgencyLocation
unconditionally in vehiclesForAgencyHandler, which introduces a new failure path
for requests that do not include the time query param. Move the
loadAgencyLocation(agency.ID, agency.Timezone) call inside the timeParam branch
in the handler so it is only executed when ParseTimeParameter is needed, and
keep the existing api.validationErrorResponse and api.serverErrorResponse
handling around that branch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 547f3b29-c869-4f07-b6c2-5bc288e01f32
📒 Files selected for processing (2)
internal/restapi/vehicles_for_agency_handler.gointernal/restapi/vehicles_for_agency_handler_test.go
Loading the agency timezone unconditionally risks a 500 error even when the time parameter is absent. Moving this call inside the if block ensures it only runs when needed, improving performance and preventing regressions. Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|



Summary
Fixes a spec gap in the
vehicles-for-agencyendpoint where thetimerequest parameter was previously ignored. The handler now properly parses the supplied time to use as the reference time, falling back to the server clock if absent, as required by the OpenAPI spec.Problem
According to the specification, the
timeparameter should set the reference time used for trip resolution. However, the handler was unconditionally usingapi.Clock.Now(). This meant that historical or future time parameters sent by clients were silently ignored.Changes
timequery parameter usingutils.ParseTimeParameter.api.Clock.Now()if thetimeparameter is absent.currentTimefor entry/trip-status timestamps.Closes #1102
Summary by CodeRabbit
/vehicles-for-agencynow uses a consistent reference time when generating vehicle and trip timestamps.timequery parameter so responses can reflect a specific moment in time.timevalues now return a clear validation error instead of producing a response.timeis not provided, the endpoint continues to use the current server time.