diff --git a/src/client/lib/src/services/api.dart b/src/client/lib/src/services/api.dart index ae6bbc7..2909e77 100644 --- a/src/client/lib/src/services/api.dart +++ b/src/client/lib/src/services/api.dart @@ -2,6 +2,7 @@ import "package:flutter/foundation.dart" show debugPrint, kDebugMode; import "package:client/data.dart"; import "package:http/http.dart" as http; +import "package:shared/graph.dart"; import "api_client.dart"; import "service.dart"; @@ -19,27 +20,20 @@ class ApiService extends Service { ? Uri(path: "api/") : Uri(scheme: "http", host: "localhost", port: 8001); - Future getPath({ + Future?> getPath({ required Coordinates start, required Coordinates end, - }) async { - final uri = _base.resolve("/path").replace( + }) => _client.getJsonList( + _base.resolve("/path").replace( queryParameters: { "start_lat": start.lat.toString(), "start_lon": start.long.toString(), "end_lat": end.lat.toString(), "end_lon": end.long.toString(), }, - ); - try { - final response = await http.get(uri); - return response.body; - // Any error should show null - // ignore: avoid_catches_without_on_clauses - } catch (error) { - return null; - } - } + ), + StopState.fromJson, + ); Future?> getRoutes() => _client.getJsonList( _base.resolve("/routes"), diff --git a/src/shared/lib/src/server/path.dart b/src/shared/lib/src/server/path.dart index e87d506..98a52bf 100644 --- a/src/shared/lib/src/server/path.dart +++ b/src/shared/lib/src/server/path.dart @@ -18,7 +18,6 @@ Response getPath(Request request) { if (path == null) { return Response.ok("No routes found", headers: corsHeaders); } - final buffer = StringBuffer(); - explainPath(path, buffer.writeln); - return Response.ok(buffer.toString(), headers: corsHeaders); + final jsonBody = encodeJsonList(path); + return Response.ok(jsonBody, headers: corsHeaders); }