Skip to content
Snippets Groups Projects
Commit fa338c76 authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

update: add CornerID to update_map endpoint

parent 93d62e1d
No related branches found
No related tags found
1 merge request!2App2
......@@ -11,7 +11,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: const DefaultPage(),
home: DefaultPage(),
);
}
}
......@@ -12,24 +12,31 @@ Future<List<Measurement>> fetchMarkerData() async {
..badCertificateCallback = // NB: temporary disable SSL certificate validation
(X509Certificate cert, String host, int port) => true;
// Request makers from API and wait for response
// Request markers from API
var request = await client.getUrl(Uri.parse(serverURI + mapEndpoint));
var response = await request.close();
var response = await request.close(); // Close response body at end of function
// Attempt to parse json if request is ok
// Parse body to JSON if request is ok
if (response.statusCode == 200) {
var responseBody = await response.transform(utf8.decoder).join();
List<dynamic> jsonData = json.decode(responseBody);
return jsonData.map((data) => Measurement.Measurement(data)).toList();
if (responseBody.isNotEmpty) {
var jsonData = json.decode(responseBody);
if (jsonData != null && jsonData is List) { // Check if jsonData is not null and is a List
return jsonData.map((data) => Measurement.Measurement(data)).toList();
} else {
throw Exception('Failed to parse marker data: Unexpected response format');
}
} else {
throw Exception('Failed to parse marker data: Empty response body');
}
} else {
print('Request failed with status: ${response.statusCode}');
throw Exception('failed to parse marker data');
throw Exception('Failed to fetch marker data: Status code ${response.statusCode}');
}
} catch (e) {
print('Request failed with error ${e}');
throw Exception('failed to connect to the server. Please check your network connection: ${e}');
print('Error fetching marker data: $e');
throw Exception('Failed to fetch marker data: ${e.toString()}');
}
}
......@@ -25,10 +25,19 @@ class Measurement {
dataList: (json['Data'] as List<dynamic>)
.map((data) => Data.fromJson(data))
.toList(),
cornerList: (json['Corner'] as List<dynamic>)
cornerList: (json['Corners'] as List<dynamic>)
.map((data) => Corner.fromJson(data))
.toList(),
bodyOfWater: json['WaterBodyName'],
/*
dataList: (json['Data'] != null && json['Data'] is List)
? (json['Data'] as List<dynamic>).map((data) => Data.fromJson(data)).toList()
: [],
cornerList: (json['Corner'] != null && json['Corner'] is List)
? (json['Corner'] as List<dynamic>).map((data) => Corner.fromJson(data)).toList()
: [],
bodyOfWater: json['WaterBodyName'] ?? '',
*/
);
}
}
......
No preview for this file type
......@@ -76,9 +76,9 @@ def get_weather(self):
weather_data.append(weather_object)
break
else: # Add error message if no weather data is found or the request fails
print(f"Request to weather API failed with status code {response.status_code}") #NB: append error message to weather_data
print(
f"Request to weather API failed with status code {response.status_code}") # NB: append error message to weather_data
status_code = response.status_code
# Set headers
......
No preview for this file type
......@@ -38,7 +38,7 @@ def get_all_markers(self, cursor, valid: bool):
for row in rows:
measurement_id = row[0]
# Create a data object for current row
# Create data object for current row
data_object = {
'Latitude': row[3],
'Longitude': row[4],
......@@ -48,8 +48,9 @@ def get_all_markers(self, cursor, valid: bool):
'Accuracy': row[8]
}
# Create a corner object for current row
# Create corner object for current row
corner_object = {
'CornerID': row[11],
'Latitude': row[12],
'Longitude': row[13]
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment