Skip to content

Commit 7dabdcb

Browse files
committed
code documentation compleated
1 parent bd2b057 commit 7dabdcb

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

packages/dart/lib/src/network/parse_aggregate.dart

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,86 @@
11
part of '../../parse_server_sdk.dart';
22

3+
/// A class that allows aggregation queries on a Parse Server class using a pipeline.
4+
///
5+
/// Example usage:
6+
/// ```dart
7+
/// final aggregate = ParseAggregate('GameScore', pipeline: {
8+
/// '\$group': {
9+
/// '_id': '\$userId',
10+
/// 'totalScore': {'\$sum': '\$score'}
11+
/// }
12+
/// });
13+
/// final response = await aggregate.execute();
14+
/// ```
315
class ParseAggregate {
16+
/// The name of the Parse class to perform the aggregation on.
417
final String className;
18+
19+
/// The aggregation pipeline operations.
20+
///
21+
/// Each operation should follow MongoDB-like syntax.
22+
/// Example:
23+
/// ```dart
24+
/// {
25+
/// '\$group': {
26+
/// '_id': '\$userId',
27+
/// 'totalScore': {'\$sum': '\$score'}
28+
/// }
29+
/// }
30+
/// ```
531
Map<String, dynamic> pipeline;
32+
33+
/// Whether to enable debug mode for this request.
634
final bool? debug;
35+
36+
/// The custom ParseClient to use for the request (optional).
737
final ParseClient? client;
38+
39+
/// If true, includes the session ID automatically in the request (optional).
840
final bool? autoSendSessionId;
41+
42+
/// Optional override for the Parse class name used in response handling.
943
final String? parseClassName;
1044

11-
ParseAggregate(this.className,{required this.pipeline,this.debug, this.client, this.autoSendSessionId, this.parseClassName});
45+
/// Creates a new [ParseAggregate] instance to perform aggregation queries.
46+
///
47+
/// [className] is required and specifies the target Parse class.
48+
/// [pipeline] must contain at least one aggregation operation.
49+
ParseAggregate(
50+
this.className, {
51+
required this.pipeline,
52+
this.debug,
53+
this.client,
54+
this.autoSendSessionId,
55+
this.parseClassName,
56+
});
1257

58+
/// Executes the aggregation query using the configured pipeline.
59+
///
60+
/// Returns a [ParseResponse] containing the results of the aggregation.
61+
/// Throws [ArgumentError] if the pipeline is empty.
1362
Future<ParseResponse> execute() async {
14-
Map<String,String> _pipeline={};
15-
if(pipeline.isEmpty){
16-
throw ArgumentError('pipeline must not be empty. Please add pipeline operations to aggregate data. Example: {"\$group": {"_id": "\$userId", "totalScore": {"\$sum": "\$score"}}} ');
17-
}
18-
else{
19-
_pipeline.addAll({'pipeline':jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList())});
63+
Map<String, String> _pipeline = {};
64+
65+
if (pipeline.isEmpty) {
66+
throw ArgumentError(
67+
'pipeline must not be empty. Please add pipeline operations to aggregate data. '
68+
'Example: {"\$group": {"_id": "\$userId", "totalScore": {"\$sum": "\$score"}}}',
69+
);
70+
} else {
71+
_pipeline.addAll({
72+
'pipeline': jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList())
73+
});
2074
}
75+
2176
final debugBool = isDebugEnabled(objectLevelDebug: debug);
2277
final result = await ParseObject(className)._client.get(
23-
Uri.parse('${ParseCoreData().serverUrl}$keyEndPointAggregate$className').replace(queryParameters: _pipeline).toString(),
24-
);
25-
print('result >>> ${result.data}');
78+
Uri.parse('${ParseCoreData().serverUrl}$keyEndPointAggregate$className').replace(
79+
queryParameters: {'pipeline': jsonEncode(pipeline.entries.map((e) => {e.key: e.value}).toList())}
80+
).toString(),
81+
);
82+
83+
2684
return handleResponse<ParseObject>(
2785
ParseObject(className),
2886
result,

0 commit comments

Comments
 (0)