diff --git a/packages/gridproxy_client/lib/models/contracts.dart b/packages/gridproxy_client/lib/models/contracts.dart index d19304a7..90174c4e 100644 --- a/packages/gridproxy_client/lib/models/contracts.dart +++ b/packages/gridproxy_client/lib/models/contracts.dart @@ -90,6 +90,7 @@ class ContractInfo { String state; int twin_id; String type; + int? nodeId; ContractInfo({ required this.contract_id, @@ -98,6 +99,7 @@ class ContractInfo { required this.state, required this.twin_id, required this.type, + this.nodeId, }); factory ContractInfo.fromJson(Map json) { @@ -122,6 +124,7 @@ class ContractInfo { return ContractInfo( contract_id: json['contract_id'] ?? 0, + nodeId: json['details']['nodeId'] ?? '', created_at: json['created_at'] ?? 0, details: details, state: json['state'] ?? '', @@ -201,7 +204,7 @@ class ContractInfoQueryParams { int? node_id; String? name; ContractTypes? type; - ContractState? state; + List? state; String? deployment_data; String? deployment_hash; int? number_of_public_ips; diff --git a/packages/gridproxy_client/lib/src/client.dart b/packages/gridproxy_client/lib/src/client.dart index e148a197..6be3fd87 100644 --- a/packages/gridproxy_client/lib/src/client.dart +++ b/packages/gridproxy_client/lib/src/client.dart @@ -19,29 +19,36 @@ class GridProxyClient { Future getRequest( String path, Map? queryParameters) async { try { - final convertedQueryParameters = queryParameters - ?.map((key, value) => MapEntry(key, value?.toString() ?? '')); + final Map encodedQueryParams = {}; + queryParameters?.forEach((key, value) { + if (value is List) { + encodedQueryParams[key] = value.map((e) => e.toString()).join(','); + } else if (value != null) { + encodedQueryParams[key] = value.toString(); + } + }); final uri = Uri.parse(baseUrl); final scheme = uri.scheme; final host = uri.host; - final requestUri = convertedQueryParameters != null && - convertedQueryParameters.isNotEmpty + final requestUri = encodedQueryParams.isNotEmpty ? (scheme == 'https' - ? Uri.https(host, path, convertedQueryParameters) - : Uri.http(host, path, convertedQueryParameters)) + ? Uri.https(host, path, encodedQueryParams) + : Uri.http(host, path, encodedQueryParams)) : (scheme == 'https' ? Uri.https(host, path) : Uri.http(host, path)); + final response = await http.get(requestUri); if (response.statusCode == 200) { final jsonData = json.decode(response.body); return jsonData; } else { - throw Exception('Failed to load data got: ${response.body}'); + throw Exception( + 'Failed to load data. Status: ${response.statusCode}, Body: ${response.body}'); } } catch (e) { - throw Exception('Error: $e'); + throw Exception('Error during GET request to $path: $e'); } } }