Skip to content

Commit

Permalink
opentripplanner#52 Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jspetrak committed Jul 1, 2024
1 parent 1a476df commit 4c538ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
12 changes: 3 additions & 9 deletions src/main/java/org/opentripplanner/client/OtpApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,12 @@ public Stop stop(String gtfsId) throws IOException {
return deserialize(jsonNode, "/data/stop", Stop.class);
}

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

try {
final var jsonNode = sendRequest(formattedQuery);
var type = listType(Stop.class);
return deserializeList(jsonNode, type, "/data/stops");
} catch (IOException e) {
LOG.error("Could not fetch stops with name mask '{}'", nameMask, e);
return List.of();
}
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/opentripplanner/client/model/Stop.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record Stop(
String name,
@JsonProperty("gtfsId") String id,
Optional<String> code,
Optional<String> vehicleMode,
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
}
4 changes: 3 additions & 1 deletion src/main/resources/queries/stop.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ query {
vehicleMode
zoneId
parentStation {
gtfsId name code
gtfsId
name
code
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/queries/stops.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ query {
vehicleMode
zoneId
parentStation {
gtfsId name code
gtfsId
name
code
}
}
}

0 comments on commit 4c538ed

Please sign in to comment.