From eed27fa5568e507c255a524185356786c877b2b8 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 7 Nov 2022 21:23:36 +0100 Subject: ready for irl test --- lib/services/authentication_service.dart | 16 --------- lib/services/istoregear_api_service.dart | 1 + lib/services/storegear_api_service.dart | 57 ++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 22 deletions(-) delete mode 100644 lib/services/authentication_service.dart (limited to 'lib/services') diff --git a/lib/services/authentication_service.dart b/lib/services/authentication_service.dart deleted file mode 100644 index ef9113e..0000000 --- a/lib/services/authentication_service.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:training_planner/services/istoregear_api_service.dart'; - -class AuthenticationService { - bool isAuthenticated = false; - String apiKey = ''; - String storedPNumber = '639174'; - String storedDaycode = '424'; - - Future authenticate(String username, String password) async { - isAuthenticated = true; - apiKey = 'test'; - storedPNumber = username; - storedDaycode = password; - return true; - } -} diff --git a/lib/services/istoregear_api_service.dart b/lib/services/istoregear_api_service.dart index adc07e0..d1a976e 100644 --- a/lib/services/istoregear_api_service.dart +++ b/lib/services/istoregear_api_service.dart @@ -6,4 +6,5 @@ import 'package:training_planner/route.dart'; abstract class IStoregearApiService { Future login(LoginRequest req); Future getRoutes(); + Future getRoute(String tripkey); } diff --git a/lib/services/storegear_api_service.dart b/lib/services/storegear_api_service.dart index ecd0c94..109c17b 100644 --- a/lib/services/storegear_api_service.dart +++ b/lib/services/storegear_api_service.dart @@ -6,6 +6,8 @@ import 'package:training_planner/models/login_response.dart'; import 'package:training_planner/models/route_list.dart'; import 'package:training_planner/route.dart'; import 'package:training_planner/services/istoregear_api_service.dart'; +import 'package:training_planner/route.dart' as DHLRoute; +import 'package:training_planner/services/mock_route_provider_service.dart'; class StoregearApiService extends IStoregearApiService { String apiKey = ''; @@ -15,8 +17,7 @@ class StoregearApiService extends IStoregearApiService { final response = await http.post( Uri.parse('http://dhlapis.com/delivery/v1/users/login?env_type=PROD'), body: jsonEncode(req)); - debugPrint(jsonEncode(req)); - debugPrint(response.body); + if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -56,6 +57,29 @@ class StoregearApiService extends IStoregearApiService { "in_trip_scan_finished": "true", "eva_added": "true", "trip_start_request_sent": "true" + }, + { + "timeframe_key": "96870", + "trip_key": "18996871", + "trip_number": "10", + "trip_pda_status": "5", + "trip_pda_status_description": "Rit overgedragen", + "trip_sequence_number": "1", + "number_in_trip": "139", + "plate": "VND-37-B", + "damage_registration": true, + "eva": "11:11", + "trip_date": "4/11/2022", + "first_address_lat": "50.8996568140536", + "first_address_lng": "5.75238472757395", + "started": "true", + "all_tasks_finished": "false", + "start_km": "24704", + "end_km": null, + "tasks_enriched": "true", + "in_trip_scan_finished": "true", + "eva_added": "true", + "trip_start_request_sent": "true" } ] } @@ -64,14 +88,12 @@ class StoregearApiService extends IStoregearApiService { @override Future getRoutes() async { - return _getMockRouteList(); + //return _getMockRouteList(); - debugPrint('WE GOT HERE!!! ' + apiKey); final response = await http.get( Uri.parse('http://dhlapis.com/delivery/v1/routes'), headers: {'X-API-KEY': apiKey}); - debugPrint(response.body); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. @@ -80,7 +102,6 @@ class StoregearApiService extends IStoregearApiService { if (content["message"] != null) { return RouteList(routes: []); } - debugPrint('amogus'); return RouteList.fromJson(content); } else { // If the server did not return a 200 OK response, @@ -88,4 +109,28 @@ class StoregearApiService extends IStoregearApiService { throw Exception('Failed to load routes'); } } + + Future getRoute(String tripkey) async { + //return MockRouteProviderService().getRoute(int.parse(tripkey)); + + final response = await http.get( + Uri.parse( + 'http://dhlapis.com/delivery/v1/routes/' + tripkey.toString()), + headers: {'X-API-KEY': apiKey}); + + if (response.statusCode == 200) { + // If the server did return a 200 OK response, + // then parse the JSON. + + var content = jsonDecode(response.body); + if (content["message"] != null) { + return null; + } + return DHLRoute.Route.fromJson(content); + } else { + // If the server did not return a 200 OK response, + // then throw an exception. + throw Exception('Failed to load route'); + } + } } -- cgit v1.2.3-70-g09d2