-
-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathparse_aggregate.dart
More file actions
53 lines (44 loc) · 1.51 KB
/
parse_aggregate.dart
File metadata and controls
53 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
part of '../../parse_server_sdk.dart';
class ParseAggregate extends ParseObject {
ParseAggregate(
this.functionName, {
bool? debug,
ParseClient? client,
bool? autoSendSessionId,
}) : super(
functionName,
client: client,
autoSendSessionId: autoSendSessionId,
debug: debug,
) {
_path = '$keyEndPointAggregate$functionName';
}
final String functionName;
@override
late String _path;
Future<ParseResponse> execute(Map<String, dynamic> pipeline, {Map<String, String>? headers}) async {
final String uri = '${ParseCoreData().serverUrl}$_path';
Map<String, String> parameters = {};
if (pipeline.isEmpty) {
throw ArgumentError(
'pipeline must not be empty. Please add pipeline operations to aggregate data. '
'Example: {"\$group": {"_id": "\$userId", "totalScore": {"\$sum": "\$score"}}}',
);
} else {
parameters.addAll({
'pipeline': jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList())
});
_setObjectData(pipeline);
}
try {
print(Uri.parse(uri).replace(queryParameters: parameters).toString());
final ParseNetworkResponse result = await _client.get(
Uri.parse(uri).replace(queryParameters: parameters).toString(),
options: ParseNetworkOptions(headers: headers)
);
return ParseResponse.fromParseNetworkResponse(result);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.execute, _debug, parseClassName);
}
}
}