feat(api_handler): properly return more types for API requests

This commit is contained in:
fbachus
2026-07-22 02:28:54 +02:00
parent e71492141e
commit 4b499d63a6
+29 -14
View File
@@ -67,9 +67,12 @@ class ApiHandler {
); );
final httpPackageJson = final httpPackageJson =
json.decode(jsonResponse.body) as Map<String, dynamic>; json.decode(jsonResponse.body) as Map<String, dynamic>;
final stationList = httpPackageJson["stopLocationOrCoordLocation"].map( final stationList = httpPackageJson["stopLocationOrCoordLocation"]
(x) => Station.fromJson(x["StopLocation"]), .map(
); (x) => Station.fromJson(x["StopLocation"]),
)
.toList()
.cast<Station>();
return stationList; return stationList;
} }
@@ -139,13 +142,16 @@ class ApiHandler {
); );
final httpPackageJson = final httpPackageJson =
json.decode(jsonResponse.body) as Map<String, dynamic>; json.decode(jsonResponse.body) as Map<String, dynamic>;
List<Departure> departureList = httpPackageJson["Departure"].map( List<Departure> departureList = httpPackageJson["Departure"]
(x) => Departure.fromJson(x), .map(
); (x) => Departure.fromJson(x),
)
.toList()
.cast<Departure>();
return departureList; return departureList;
} }
static Future<List<String>> trip( static Future<List<Segment>> trip(
String originId, String originId,
String destinationId, { String destinationId, {
String? via, String? via,
@@ -179,13 +185,17 @@ class ApiHandler {
); );
final httpPackageJson = final httpPackageJson =
json.decode(jsonResponse.body) as Map<String, dynamic>; json.decode(jsonResponse.body) as Map<String, dynamic>;
final idList = httpPackageJson["Trip"].map( // TODO: here lurk problems - do we get a list of list of segments? can't cast it
(x) => x["LegList"]["Leg"].map((y) => y["JourneyDetail"]["ref"]), // what do we want from this?
); List<Segment> SegmentList = httpPackageJson["Trip"]
return idList; .map(
(x) => x["LegList"]["Leg"].map((y) => Segment.fromJson(y)),
)
.toList();
return SegmentList;
} }
static Future<List<String>> tripDetail( static Future<List<Departure>> tripDetail(
String id, { String id, {
String? date, String? date,
String? fromId, String? fromId,
@@ -206,7 +216,12 @@ class ApiHandler {
); );
final httpPackageJson = final httpPackageJson =
json.decode(jsonResponse.body) as Map<String, dynamic>; json.decode(jsonResponse.body) as Map<String, dynamic>;
final idList = httpPackageJson["Stops"]["Stop"].map((x) => x["id"]); final DepartureList = httpPackageJson["Stops"]["Stop"]
return idList; .map(
(x) => Departure.fromJson(x),
)
.toList()
.cast<Departure>();
return DepartureList;
} }
} }