Server sends StopState instead of String

This commit is contained in:
Levi Lesches 2025-05-04 20:19:51 -04:00
parent e8de6475c7
commit 1c5c6c9f11
2 changed files with 9 additions and 16 deletions

View file

@ -2,6 +2,7 @@ import "package:flutter/foundation.dart" show debugPrint, kDebugMode;
import "package:client/data.dart"; import "package:client/data.dart";
import "package:http/http.dart" as http; import "package:http/http.dart" as http;
import "package:shared/graph.dart";
import "api_client.dart"; import "api_client.dart";
import "service.dart"; import "service.dart";
@ -19,27 +20,20 @@ class ApiService extends Service {
? Uri(path: "api/") ? Uri(path: "api/")
: Uri(scheme: "http", host: "localhost", port: 8001); : Uri(scheme: "http", host: "localhost", port: 8001);
Future<String?> getPath({ Future<List<StopState>?> getPath({
required Coordinates start, required Coordinates start,
required Coordinates end, required Coordinates end,
}) async { }) => _client.getJsonList(
final uri = _base.resolve("/path").replace( _base.resolve("/path").replace(
queryParameters: { queryParameters: {
"start_lat": start.lat.toString(), "start_lat": start.lat.toString(),
"start_lon": start.long.toString(), "start_lon": start.long.toString(),
"end_lat": end.lat.toString(), "end_lat": end.lat.toString(),
"end_lon": end.long.toString(), "end_lon": end.long.toString(),
}, },
),
StopState.fromJson,
); );
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;
}
}
Future<List<Route>?> getRoutes() => _client.getJsonList( Future<List<Route>?> getRoutes() => _client.getJsonList(
_base.resolve("/routes"), _base.resolve("/routes"),

View file

@ -18,7 +18,6 @@ Response getPath(Request request) {
if (path == null) { if (path == null) {
return Response.ok("No routes found", headers: corsHeaders); return Response.ok("No routes found", headers: corsHeaders);
} }
final buffer = StringBuffer(); final jsonBody = encodeJsonList(path);
explainPath(path, buffer.writeln); return Response.ok(jsonBody, headers: corsHeaders);
return Response.ok(buffer.toString(), headers: corsHeaders);
} }