Skip to content

Add support for coordinate via point in the GTFS GraphQL API - #6490

Merged
optionsome merged 6 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:gtfs-api-via-coordinates
Mar 13, 2025
Merged

Add support for coordinate via point in the GTFS GraphQL API#6490
optionsome merged 6 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:gtfs-api-via-coordinates

Conversation

@optionsome

Copy link
Copy Markdown
Member

Summary

Adds support for coordinate via point in the GTFS GraphQL API.

Issue

Related to #4887 (comment)

Unit tests

Updated GraphQL integration test.

Documentation

None

Changelog

From title

@optionsome optionsome added the !Improvement A functional improvement or micro feature label Feb 25, 2025
@codecov

codecov Bot commented Feb 25, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 70.20%. Comparing base (1f55690) to head (902a172).
Report is 82 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...ripplanner/apis/gtfs/mapping/CoordinateMapper.java 57.14% 1 Missing and 2 partials ⚠️
...ntripplanner/apis/gtfs/generated/GraphQLTypes.java 60.00% 2 Missing ⚠️
...s/gtfs/mapping/routerequest/ViaLocationMapper.java 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #6490   +/-   ##
==========================================
  Coverage      70.20%   70.20%           
- Complexity     18312    18315    +3     
==========================================
  Files           2080     2083    +3     
  Lines          77182    77226   +44     
  Branches        7831     7833    +2     
==========================================
+ Hits           54182    54219   +37     
- Misses         20231    20235    +4     
- Partials        2769     2772    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@optionsome
optionsome force-pushed the gtfs-api-via-coordinates branch from 1cf25c4 to 86707e8 Compare March 4, 2025 08:12
@optionsome
optionsome marked this pull request as ready for review March 4, 2025 08:13
@optionsome
optionsome requested a review from a team as a code owner March 4, 2025 08:13
Comment on lines +61 to +67
private static List<WgsCoordinate> mapCoordinate(@Nullable Object coordinate) {
if (coordinate == null) {
return List.of();
}
var map = (Map<String, Object>) coordinate;
return List.of(new WgsCoordinate((Double) map.get("latitude"), (Double) map.get("longitude")));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting the Coordinate mapping into a separate class so it can be reused.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PlanCoordinateInput is not defined in this PR. If in use there should already be a mapper for it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For origin and destination, we map the GraphQL coordinates directly into GenericLocation objects. Here we parse the coordinates into WgsCoordinate objects. However, I think in the future, there will be other use cases for parsing these mapping coordinates to WgsCoordinates so I'll extract the mapping elsewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note, the way how the coordinate is read here is not what I've usually used. Sometimes we have to use this untyped map for parsing the arguments but often it's possible to use the generated types to parse the arguments. @leonardehrenfried originally wrote this class so I'm not sure if we run into some bug or not in this case if we used the generated types.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to change it. I vaguely remember that I tried it but there was a problem. Sorry, I cannot remember more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work 902a172 . I think the issue might have been for mapping a list of objects. I didn't use the types for the list of via points.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coordinate mapping should be moved out even if there are different ways of doing it. Also, this mapper will then of cause just use the extracted mapping.

@t2gran t2gran added this to the 2.8 (next release) milestone Mar 12, 2025
@optionsome
optionsome merged commit 7852115 into opentripplanner:dev-2.x Mar 13, 2025
@optionsome
optionsome deleted the gtfs-api-via-coordinates branch March 13, 2025 13:27
t2gran pushed a commit that referenced this pull request Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Improvement A functional improvement or micro feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants