Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#52 Stop fulltext search API #53

Merged
Merged
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
8 changes: 8 additions & 0 deletions src/main/java/org/opentripplanner/client/OtpApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ public Stop stop(String gtfsId) throws IOException {
return deserialize(jsonNode, "/data/stop", Stop.class);
}

public List<Stop> stops(String nameMask) throws IOException {
var stopQuery = GraphQLQueries.stops();
var formattedQuery = stopQuery.formatted(nameMask);

final var jsonNode = sendRequest(formattedQuery);
return deserializeList(jsonNode, listType(Stop.class), "/data/stops");
}

private <T> T deserialize(JsonNode jsonNode, String path, Class<T> clazz) throws IOException {
try {
var plan = jsonNode.at(path);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/opentripplanner/client/model/Stop.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record Stop(
String name,
@JsonProperty("gtfsId") String id,
Optional<String> code,
Optional<VehicleMode> vehicleMode,
Optional<String> zoneId,
ParentStation parentStation) {
public Stop {
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/opentripplanner/client/model/VehicleMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.opentripplanner.client.model;

public enum VehicleMode {
AIRPLANE,
BICYCLE,
BUS,
CABLE_CAR,
CAR,
COACH,
FERRY,
FLEX,
@Deprecated
FLEXIBLE,
FUNICULAR,
GONDOLA,
@Deprecated
LEG_SWITCH,
RAIL,
SCOOTER,
SUBWAY,
TRAM,
CARPOOL,
TAXI,
TRANSIT,
WALK,
TROLLEYBUS,
MONORAIL
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static String stop() {
return loadQuery("stop");
}

public static String stops() {
return loadQuery("stops");
}

private static String loadQuery(String name) {
var is =
GraphQLQueries.class
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/queries/stop.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ query {
name
gtfsId
code
vehicleMode
zoneId
parentStation {
gtfsId
name
code
}
}
}
14 changes: 14 additions & 0 deletions src/main/resources/queries/stops.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
query {
stops(name: "%s") {
name
gtfsId
code
vehicleMode
zoneId
parentStation {
gtfsId
name
code
}
}
}
14 changes: 14 additions & 0 deletions src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ public void stop() throws IOException {
assertNotNull(result.id());
}

@Test
public void stops() throws IOException {
var result = client.stops("Oslo");

LOG.info("Received stops");

assertNotNull(result);
assertFalse(result.isEmpty());

var stop = result.get(0);

assertNotNull(stop.id());
}

@Disabled
@Test
public void seattleFares() throws IOException {
Expand Down