Skip to content

Commit 8ad7e19

Browse files
committed
no message
1 parent ec71870 commit 8ad7e19

File tree

5 files changed

+72
-56
lines changed

5 files changed

+72
-56
lines changed

packages/dart/example/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Future<void> main() async {
1414
..set('Name', 'Ketogenic')
1515
..set('Fat', 65);
1616

17+
// ParseAggregate('className', pipeline: {}).execute();
18+
1719
var response = await dietPlan.save();
1820

1921
if (response.success) {

packages/dart/lib/parse_server_sdk.dart

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:cross_file/cross_file.dart';
1111
import 'package:dio/dio.dart';
1212
import 'package:meta/meta.dart';
1313
import 'package:mime/mime.dart';
14+
import 'package:parse_server_sdk/src/utils/url_replace.dart';
1415
import 'package:path/path.dart' as path;
1516
import 'package:sembast/sembast.dart';
1617
import 'package:sembast/sembast_io.dart';
@@ -29,111 +30,59 @@ export 'src/network/parse_dio_client.dart';
2930
export 'src/network/parse_http_client.dart';
3031

3132
part 'src/base/parse_constants.dart';
32-
3333
part 'src/data/parse_core_data.dart';
34-
3534
part 'src/data/parse_subclass_handler.dart';
36-
3735
part 'src/enums/parse_enum_api_rq.dart';
38-
3936
part 'src/network/options.dart';
40-
37+
part 'src/network/parse_aggregate.dart';
4138
part 'src/network/parse_client.dart';
42-
4339
part 'src/network/parse_connectivity.dart';
44-
4540
part 'src/network/parse_live_query.dart';
46-
4741
part 'src/network/parse_query.dart';
48-
4942
part 'src/objects/parse_acl.dart';
50-
5143
part 'src/objects/parse_array.dart';
52-
5344
part 'src/objects/parse_base.dart';
54-
5545
part 'src/objects/parse_cloneable.dart';
56-
5746
part 'src/objects/parse_config.dart';
58-
5947
part 'src/objects/parse_error.dart';
60-
6148
part 'src/objects/parse_exception.dart';
62-
6349
part 'src/objects/parse_file.dart';
64-
6550
part 'src/objects/parse_file_base.dart';
66-
6751
part 'src/objects/parse_file_web.dart';
68-
6952
part 'src/objects/parse_function.dart';
70-
7153
part 'src/objects/parse_geo_point.dart';
72-
7354
part 'src/objects/parse_installation.dart';
74-
7555
part 'src/objects/parse_number.dart';
76-
7756
part 'src/objects/parse_object.dart';
78-
7957
part 'src/objects/parse_operation/parse_add_operation.dart';
80-
8158
part 'src/objects/parse_operation/parse_add_relation_operation.dart';
82-
8359
part 'src/objects/parse_operation/parse_add_unique_operation.dart';
84-
8560
part 'src/objects/parse_operation/parse_increment_operation.dart';
86-
8761
part 'src/objects/parse_operation/parse_operation.dart';
88-
8962
part 'src/objects/parse_operation/parse_remove_operation.dart';
90-
9163
part 'src/objects/parse_operation/parse_remove_relation_operation.dart';
92-
9364
part 'src/objects/parse_relation.dart';
94-
9565
part 'src/objects/parse_response.dart';
96-
9766
part 'src/objects/parse_save_state_aware_child.dart';
98-
9967
part 'src/objects/parse_session.dart';
100-
10168
part 'src/objects/parse_user.dart';
102-
10369
part 'src/objects/parse_x_file.dart';
104-
10570
part 'src/objects/response/parse_error_response.dart';
106-
10771
part 'src/objects/response/parse_exception_response.dart';
108-
10972
part 'src/objects/response/parse_response_builder.dart';
110-
11173
part 'src/objects/response/parse_response_utils.dart';
112-
11374
part 'src/objects/response/parse_success_no_results.dart';
114-
11575
part 'src/storage/core_store.dart';
116-
11776
part 'src/storage/core_store_memory.dart';
118-
11977
part 'src/storage/core_store_sem_impl.dart';
120-
12178
part 'src/storage/xxtea_codec.dart';
122-
12379
part 'src/utils/parse_date_format.dart';
124-
12580
part 'src/utils/parse_decoder.dart';
126-
12781
part 'src/utils/parse_encoder.dart';
128-
12982
part 'src/utils/parse_live_list.dart';
130-
13183
part 'src/utils/parse_logger.dart';
132-
13384
part 'src/utils/parse_login_helpers.dart';
134-
13585
part 'src/utils/parse_utils.dart';
136-
13786
part 'src/utils/valuable.dart';
13887

13988
class Parse {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
part of '../../parse_server_sdk.dart';
2+
3+
class ParseAggregate {
4+
final String className;
5+
final Map<String, dynamic> pipeline;
6+
final bool? debug;
7+
final ParseClient? client;
8+
final bool? autoSendSessionId;
9+
final String? parseClassName;
10+
11+
ParseAggregate(this.className,{required this.pipeline,this.debug, this.client, this.autoSendSessionId, this.parseClassName});
12+
13+
Future<ParseResponse> execute() async {
14+
if(pipeline.isEmpty){
15+
throw ArgumentError('pipeline must not be empty. Please add pipeline operations to aggregate data. Example: {"\$group": {"_id": "\$userId", "totalScore": {"\$sum": "\$score"}}} ');
16+
}
17+
final debugBool = isDebugEnabled(objectLevelDebug: debug);
18+
final result = await ParseHTTPClient().get(
19+
'${ParseCoreData().serverUrl}$keyEndPointAggregate/$className',
20+
replace: UrlReplace(queryParameters: pipeline)
21+
);
22+
return handleResponse<ParseObject>(
23+
this,
24+
result,
25+
ParseApiRQ.get,
26+
debugBool,
27+
parseClassName ?? 'ParseBase',
28+
);
29+
}
30+
}

packages/dart/lib/src/network/parse_http_client.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:convert';
2-
import 'package:universal_io/io.dart';
32

43
import 'package:http/http.dart' as http;
5-
64
import 'package:parse_server_sdk/parse_server_sdk.dart';
5+
import 'package:parse_server_sdk/src/utils/url_replace.dart';
6+
import 'package:universal_io/io.dart';
77

88
import 'http_client_io.dart' if (dart.library.js) 'http_client_js.dart';
99

@@ -30,9 +30,20 @@ class ParseHTTPClient extends ParseClient {
3030
String path, {
3131
ParseNetworkOptions? options,
3232
ProgressCallback? onReceiveProgress,
33+
UrlReplace? replace
3334
}) async {
3435
final http.Response response = await _client.get(
35-
Uri.parse(path),
36+
replace != null ? Uri.parse(path).replace(
37+
scheme:replace.scheme,
38+
userInfo:replace.userInfo,
39+
host:replace.host,
40+
port:replace.port,
41+
path:replace.path,
42+
pathSegments:replace.pathSegments,
43+
query:replace.query,
44+
queryParameters:replace.queryParameters,
45+
fragment:replace.fragment,
46+
): Uri.parse(path),
3647
headers: options?.headers,
3748
);
3849
return ParseNetworkResponse(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class UrlReplace{
2+
String? scheme;
3+
String? userInfo;
4+
String? host;
5+
int? port;
6+
String? path;
7+
Iterable<String>? pathSegments;
8+
String? query;
9+
Map<String, dynamic>? queryParameters;
10+
String? fragment;
11+
12+
UrlReplace({
13+
this.scheme,
14+
this.userInfo,
15+
this.host,
16+
this.port,
17+
this.path,
18+
this.pathSegments,
19+
this.query,
20+
this.queryParameters,
21+
this.fragment,
22+
});
23+
24+
}

0 commit comments

Comments
 (0)