Skip to content

refactor: extract ParseLocationParams helper to remove duplication across location handlers#746

Open
AhmedAlian7 wants to merge 1 commit intoOneBusAway:mainfrom
AhmedAlian7:refactor/extract-location-params-helper
Open

refactor: extract ParseLocationParams helper to remove duplication across location handlers#746
AhmedAlian7 wants to merge 1 commit intoOneBusAway:mainfrom
AhmedAlian7:refactor/extract-location-params-helper

Conversation

@AhmedAlian7
Copy link
Copy Markdown
Contributor

Description

Extracts the duplicated location query parameter parsing logic shared across
three handlers into a single reusable helper.

Closes #745

Changes

internal/utils/api.go

  • Added LocationParams struct holding Lat, Lon, LatSpan, LonSpan, Radius
  • Added ParseLocationParams(q url.Values) which reuses existing ParseRequiredFloatParam
    for lat/lon (required) and ParseFloatParam for the optional fields
  • Returns nil struct pointer on any validation error, consistent with existing error
    accumulation pattern

internal/restapi/stops_for_location_handler.go

  • Replaced 5 individual Parse*FloatParam calls with a single utils.ParseLocationParams call

internal/restapi/routes_for_location_handler.go

  • Same replacement as above

internal/restapi/trips_for_location_handler.go

  • Replaced 4 Parse*FloatParam calls in parseAndValidateRequest with
    utils.ParseLocationParams
  • locParams.Radius is intentionally ignored — this handler does not use it

internal/utils/api_test.go

Added 8 test cases for ParseLocationParams:

Testing

make test
make lint
go fmt ./...

@aaronbrethorst
Copy link
Copy Markdown
Member

@AhmedAlian7 please fix the merge conflicts!

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.

refactor: extract shared ParseLocationParams helper to eliminate duplication across location-based handlers

2 participants