-
-
Notifications
You must be signed in to change notification settings - Fork 207
Add Aggregate Query Support to Parse Flutter SDK #1041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mskayali
wants to merge
9
commits into
parse-community:master
Choose a base branch
from
mskayali:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ad7e19
no message
mskayali e65a3f5
packages updated
mskayali c093ff1
Aggregate done!
mskayali 29d83f5
no message
mskayali 3a4feb6
Pipeline bug fixed (complex aggregates supported)
mskayali bd2b057
no message
mskayali 7dabdcb
code documentation compleated
mskayali 953b54a
Aggregate result type changed to ParseNetworkResponse to handle custo…
mskayali a255b0a
ParseAggregate method updated, small bugs fixed
mskayali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()); | ||
mskayali marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
part of '../../parse_server_sdk.dart'; | ||
|
||
class ParseJobs extends ParseObject { | ||
/// Creates a new cloud function object | ||
/// | ||
/// {https://docs.parseplatform.org/cloudcode/guide/} | ||
ParseJobs( | ||
this.functionName, { | ||
bool? debug, | ||
ParseClient? client, | ||
bool? autoSendSessionId, | ||
}) : super( | ||
functionName, | ||
client: client, | ||
autoSendSessionId: autoSendSessionId, | ||
debug: debug, | ||
) { | ||
_path = '$keyEndPointJobs$functionName'; | ||
} | ||
|
||
final String functionName; | ||
|
||
@override | ||
// ignore: overridden_fields | ||
late String _path; | ||
|
||
/// Executes a cloud function | ||
/// | ||
/// To add the parameters, create an object and call [set](value to set) | ||
Future<ParseResponse> execute({Map<String, dynamic>? parameters, Map<String, String>? headers}) async { | ||
final String uri = '${ParseCoreData().serverUrl}$_path'; | ||
if (parameters != null) { | ||
_setObjectData(parameters); | ||
} | ||
try { | ||
final ParseNetworkResponse result = await _client.post(uri, options: ParseNetworkOptions(headers: headers), data: json.encode(_getObjectData())); | ||
return handleResponse<ParseJobs>(this, result, ParseApiRQ.execute, _debug, parseClassName); | ||
} on Exception catch (e) { | ||
return handleException(e, ParseApiRQ.execute, _debug, parseClassName); | ||
} | ||
} | ||
|
||
/// Executes a cloud function that returns a ParseObject type | ||
/// | ||
/// To add the parameters, create an object and call [set](value to set) | ||
Future<ParseResponse> executeObjectFunction<T extends ParseObject>({Map<String, dynamic>? parameters, Map<String, String>? headers}) async { | ||
final String uri = '${ParseCoreData().serverUrl}$_path'; | ||
if (parameters != null) { | ||
_setObjectData(parameters); | ||
} | ||
try { | ||
final ParseNetworkResponse result = await _client.post(uri, options: ParseNetworkOptions(headers: headers), data: json.encode(_getObjectData())); | ||
return handleResponse<T>(this, result, ParseApiRQ.executeObjectionFunction, _debug, parseClassName); | ||
} on Exception catch (e) { | ||
return handleException(e, ParseApiRQ.executeObjectionFunction, _debug, parseClassName); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.