Skip to content

Commit

Permalink
Merge pull request #53 from jspetrak/52-stop-fulltext-api
Browse files Browse the repository at this point in the history
#52 Stop fulltext search API
  • Loading branch information
leonardehrenfried authored Jul 1, 2024
2 parents ceb5abc + 4c538ed commit fe29c48
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 0 deletions.
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

0 comments on commit fe29c48

Please sign in to comment.