Skip to content

Commit 6ac0f9d

Browse files
committed
Edit ContractInfo to include nodeId, edit state to be a list
1 parent dabf623 commit 6ac0f9d

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

packages/gridproxy_client/lib/models/contracts.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ContractInfo {
9090
String state;
9191
int twin_id;
9292
String type;
93+
int? nodeId;
9394

9495
ContractInfo({
9596
required this.contract_id,
@@ -98,6 +99,7 @@ class ContractInfo {
9899
required this.state,
99100
required this.twin_id,
100101
required this.type,
102+
this.nodeId,
101103
});
102104

103105
factory ContractInfo.fromJson(Map<String, dynamic> json) {
@@ -122,6 +124,7 @@ class ContractInfo {
122124

123125
return ContractInfo(
124126
contract_id: json['contract_id'] ?? 0,
127+
nodeId: json['details']['nodeId'] ?? '',
125128
created_at: json['created_at'] ?? 0,
126129
details: details,
127130
state: json['state'] ?? '',
@@ -201,7 +204,7 @@ class ContractInfoQueryParams {
201204
int? node_id;
202205
String? name;
203206
ContractTypes? type;
204-
ContractState? state;
207+
List<ContractState>? state;
205208
String? deployment_data;
206209
String? deployment_hash;
207210
int? number_of_public_ips;

packages/gridproxy_client/lib/src/client.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,36 @@ class GridProxyClient {
1919
Future<dynamic> getRequest(
2020
String path, Map<String, dynamic>? queryParameters) async {
2121
try {
22-
final convertedQueryParameters = queryParameters
23-
?.map((key, value) => MapEntry(key, value?.toString() ?? ''));
22+
final Map<String, String> encodedQueryParams = {};
23+
queryParameters?.forEach((key, value) {
24+
if (value is List) {
25+
encodedQueryParams[key] = value.map((e) => e.toString()).join(',');
26+
} else if (value != null) {
27+
encodedQueryParams[key] = value.toString();
28+
}
29+
});
2430

2531
final uri = Uri.parse(baseUrl);
2632
final scheme = uri.scheme;
2733
final host = uri.host;
2834

29-
final requestUri = convertedQueryParameters != null &&
30-
convertedQueryParameters.isNotEmpty
35+
final requestUri = encodedQueryParams.isNotEmpty
3136
? (scheme == 'https'
32-
? Uri.https(host, path, convertedQueryParameters)
33-
: Uri.http(host, path, convertedQueryParameters))
37+
? Uri.https(host, path, encodedQueryParams)
38+
: Uri.http(host, path, encodedQueryParams))
3439
: (scheme == 'https' ? Uri.https(host, path) : Uri.http(host, path));
40+
3541
final response = await http.get(requestUri);
3642

3743
if (response.statusCode == 200) {
3844
final jsonData = json.decode(response.body);
3945
return jsonData;
4046
} else {
41-
throw Exception('Failed to load data got: ${response.body}');
47+
throw Exception(
48+
'Failed to load data. Status: ${response.statusCode}, Body: ${response.body}');
4249
}
4350
} catch (e) {
44-
throw Exception('Error: $e');
51+
throw Exception('Error during GET request to $path: $e');
4552
}
4653
}
4754
}

0 commit comments

Comments
 (0)