Skip to content

feat: Add query constraint wherePolygonContains to determine whether a point in within a polygon #778

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

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [3.1.11](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.10...dart-3.1.11) (2023-01-20)

### Features

* Add query constraint `wherePolygonContains` to determine whether a point in within a polygon ([#777](https://github.com/parse-community/Parse-SDK-Flutter/issues/777))

## [3.1.10](https://github.com/parse-community/Parse-SDK-Flutter/compare/dart-3.1.9...dart-3.1.10) (2023-01-16)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/lib/src/base/parse_constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
part of flutter_parse_sdk;

// Library
const String keySdkVersion = '3.1.10';
const String keySdkVersion = '3.1.11';
const String keyLibraryName = 'Flutter Parse SDK';

// End Points
Expand Down
9 changes: 9 additions & 0 deletions packages/dart/lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ class QueryBuilder<T extends ParseObject> {
_singleQuery, '"$column":{"\$geoWithin":${jsonEncode(dictionary)}}'));
}

/// Add a constraint to the query that requires a particular key's coordinates that contains a point
void wherePolygonContains(String column, ParseGeoPoint point) {
final double latitude = point.latitude;
final double longitude = point.longitude;

queries.add(MapEntry<String, dynamic>(_singleQuery,
'"$column":{"\$geoIntersects":{"\$point":{"__type":"GeoPoint","latitude":$latitude,"longitude":$longitude}}}'));
}

/// Add a constraint to the query that requires a particular key's value match another QueryBuilder
void whereMatchesQuery<E extends ParseObject>(
String column, QueryBuilder<E> query) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk
description: Dart plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
version: 3.1.10
version: 3.1.11
homepage: https://github.com/parse-community/Parse-SDK-Flutter

environment:
Expand Down
75 changes: 75 additions & 0 deletions packages/dart/test/parse_query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,80 @@ void main() {

expect(result.query, expectedQuery.query);
});

test('wherePolygonContains', () async {
// arrange
final QueryBuilder<ParseObject> queryBuilder =
QueryBuilder<ParseObject>(ParseObject('TEST_SCHEMA', client: client));
double latitude = 84.17724609375;
double longitude = -53.69670647530323;
ParseGeoPoint point =
ParseGeoPoint(latitude: latitude, longitude: longitude);
queryBuilder.wherePolygonContains("geometry", point);

var desiredOutput = {
"results": [
{
"objectId": "eT9muOxBTK",
"createdAt": "2022-07-25T13:46:06.092Z",
"updatedAt": "2022-07-25T13:46:23.586Z",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[84.17724609375, -53.69670647530323],
[83.1884765625, -54.61025498157913],
[84.814453125, -55.14120964449505],
[85.67138671875, -54.40614309031968],
[84.17724609375, -53.69670647530323]
]
]
}
}
]
};

when(client.get(
any,
options: anyNamed("options"),
onReceiveProgress: anyNamed("onReceiveProgress"),
)).thenAnswer((_) async => ParseNetworkResponse(
statusCode: 200, data: jsonEncode(desiredOutput)));

// act
ParseResponse response = await queryBuilder.query();

ParseObject parseObject = response.results?.first;

final Uri result = Uri.parse(verify(client.get(
captureAny,
options: anyNamed("options"),
onReceiveProgress: anyNamed("onReceiveProgress"),
)).captured.single);

var queryDesiredOutput = {
"geometry": {
"\$geoIntersects": {
"\$point": {
"__type": "GeoPoint",
"latitude": latitude,
"longitude": longitude
}
}
}
};
final Uri expectedQuery =
Uri(query: 'where=' + jsonEncode(queryDesiredOutput));

// assert
expect(response.results?.first, isA<ParseObject>());

expect(parseObject.objectId, "eT9muOxBTK");
expect(parseObject.containsKey("geometry"), true);

expect(result.path, '/classes/TEST_SCHEMA');

expect(result.query, expectedQuery.query);
});
});
}