Skip to content

Commit c79ac39

Browse files
RodrigoSMarquesphillwiggins
authored andcommitted
BugFix ParseQuery, ParseFile, ParseEncoder (#132)
* Release/v1.0.16 (#124) * Merge branches 'develop' and 'master' of https://github.com/phillwiggins/flutter_parse_sdk # Conflicts: # .idea/libraries/Dart_Packages.xml # lib/src/objects/parse_file.dart # lib/src/objects/parse_user.dart # pubspec.yaml * Correct null pointer from success response with empty body * Code tidy * Added url port support Added lint rules Added object population on update and save * Updated dependency uuid (#120) * Fixed date query - Needs testing * Added date formatting Added cURL logging * updating path_provider dependency (#121) * Update README.md to support code highlight (#126) * Bugix after release v.1.016 Many bugfix after Bugix after release v.1.016 * Function toPointer() Function toPointer() in ParseObject * Bugix after release v.1.016 Bugfix after Merge Pull Request release v.1.016 * Update parse_encoder.dart * Update parse_object.dart Remove blank lines
1 parent 245a1d6 commit c79ac39

File tree

8 files changed

+61
-44
lines changed

8 files changed

+61
-44
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Want to get involved? Join our Slack channel and help out! (http://flutter-parse
1111

1212
## Getting Started
1313
To install, either add to your pubspec.yaml
14-
```
14+
```yml
1515
dependencies:
1616
parse_server_sdk: ^1.0.16
1717
```
@@ -20,15 +20,15 @@ or clone this repository and add to your project. As this is an early developmen
2020
2121
Once you have the library added to your project, upon first call to your app (Similar to what your application class would be) add the following...
2222
23-
```
23+
```dart
2424
Parse().initialize(
2525
ApplicationConstants.keyApplicationId,
2626
ApplicationConstants.keyParseServerUrl);
2727
```
2828

2929
It's possible to add other params, such as ...
3030

31-
```
31+
```dart
3232
Parse().initialize(
3333
ApplicationConstants.keyApplicationId,
3434
ApplicationConstants.keyParseServerUrl,
@@ -42,7 +42,7 @@ Parse().initialize(
4242

4343
## Queries
4444
Once you have setup the project and initialised the instance, you can then retreive data from your server by calling:
45-
```
45+
```dart
4646
var apiResponse = await ParseObject('ParseTableName').getAll();
4747
4848
if (apiResponse.success){
@@ -53,7 +53,7 @@ var apiResponse = await ParseObject('ParseTableName').getAll();
5353
```
5454
Or you can get an object by its objectId:
5555

56-
```
56+
```dart
5757
var dietPlan = await DietPlan().getObject('R5EonpUDWy');
5858
5959
if (dietPlan.success) {
@@ -67,7 +67,7 @@ var dietPlan = await DietPlan().getObject('R5EonpUDWy');
6767
## Complex queries
6868
You can create complex queries to really put your database to the test:
6969

70-
```
70+
```dart
7171
var queryBuilder = QueryBuilder<DietPlan>(DietPlan())
7272
..startsWith(DietPlan.keyName, "Keto")
7373
..greaterThan(DietPlan.keyFat, 64)
@@ -110,7 +110,7 @@ The features available are:-
110110
## Objects
111111

112112
You can create custom objects by calling:
113-
```
113+
```dart
114114
var dietPlan = ParseObject('DietPlan')
115115
..set('Name', 'Ketogenic')
116116
..set('Fat', 65);
@@ -132,7 +132,7 @@ The features available are:-
132132
## Custom Objects
133133
You can create your own ParseObjects or convert your existing objects into Parse Objects by doing the following:
134134

135-
```
135+
```dart
136136
class DietPlan extends ParseObject implements ParseCloneable {
137137
138138
DietPlan() : super(_keyTableName);
@@ -155,7 +155,7 @@ class DietPlan extends ParseObject implements ParseCloneable {
155155

156156
To add a variable to an object call and retrieve it, call
157157

158-
```
158+
```dart
159159
dietPlan.set<int>('RandomInt', 8);
160160
var randomInt = dietPlan.get<int>('RandomInt');
161161
```
@@ -164,21 +164,21 @@ var randomInt = dietPlan.get<int>('RandomInt');
164164

165165
You can now save an object by calling .pin() on an instance of an object
166166

167-
```
167+
```dart
168168
dietPlan.pin();
169169
```
170170

171171
and to retrieve it
172172

173-
```
173+
```dart
174174
var dietPlan = DietPlan().fromPin('OBJECT ID OF OBJECT');
175175
```
176176

177177
## Increment Counter values in objects
178178

179179
Retrieve it, call
180180

181-
```
181+
```dart
182182
var response = await dietPlan.increment("count", 1);
183183
184184
```
@@ -187,7 +187,7 @@ var response = await dietPlan.increment("count", 1);
187187

188188
Retrieve it, call
189189

190-
```
190+
```dart
191191
var response = await dietPlan.add("listKeywords", ["a", "a","d"]);
192192
193193
var response = await dietPlan.addUnique("listKeywords", ["a", "a","d"]);
@@ -202,22 +202,22 @@ var response = await dietPlan.remove("listKeywords", ["a"]);
202202
You can create and control users just as normal using this SDK.
203203

204204
To register a user, first create one :
205-
```
205+
```dart
206206
var user = ParseUser().create("TestFlutter", "TestPassword123", "[email protected]");
207207
```
208208
Then have the user sign up:
209209

210-
```
210+
```dart
211211
var response = await user.signUp();
212212
if (response.success) user = response.result;
213213
```
214214
You can also logout and login with the user:
215-
```
215+
```dart
216216
var response = await user.login();
217217
if (response.success) user = response.result;
218218
```
219219
Also, once logged in you can manage sessions tokens. This feature can be called after Parse().init() on startup to check for a logged in user.
220-
```
220+
```dart
221221
user = ParseUser.currentUser();
222222
```
223223
Other user features are:-
@@ -231,12 +231,12 @@ Other user features are:-
231231
## Config
232232

233233
The SDK now supports Parse Config. A map of all configs can be grabbed from the server by calling :
234-
```
234+
```dart
235235
var response = await ParseConfig().getConfigs();
236236
```
237237

238238
and to add a config:
239-
```
239+
```dart
240240
ParseConfig().addConfig('TestConfig', 'testing');
241241
```
242242

lib/src/network/parse_query.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,19 +285,22 @@ class QueryBuilder<T extends ParseObject> {
285285
MapEntry<String, dynamic> _buildQueryWithColumnValueAndOperator(
286286
MapEntry<String, dynamic> columnAndValue, String queryOperator) {
287287
final String key = columnAndValue.key;
288-
final dynamic value = convertValueToCorrectType(columnAndValue.value);
288+
final dynamic value =
289+
convertValueToCorrectType(columnAndValue.value);
289290

290291
if (queryOperator == _NO_OPERATOR_NEEDED) {
291-
return MapEntry<String, dynamic>(_NO_OPERATOR_NEEDED, '\"$key\": $value');
292+
return MapEntry<String, dynamic>(
293+
_NO_OPERATOR_NEEDED, '\"${key}\": $value');
292294
} else {
293295
String queryString = '\"$key\":';
296+
294297
final Map<String, dynamic> queryOperatorAndValueMap =
295298
Map<String, dynamic>();
296-
297299
queryOperatorAndValueMap[queryOperator] = value;
298300
final String formattedQueryOperatorAndValue =
299-
jsonEncode(queryOperatorAndValueMap);
301+
JsonEncoder().convert(queryOperatorAndValueMap);
300302
queryString += '$formattedQueryOperatorAndValue';
303+
301304
return MapEntry<String, dynamic>(key, queryString);
302305
}
303306
}

lib/src/objects/parse_base.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,4 @@ abstract class ParseBase {
205205
}
206206
return null;
207207
}
208-
209-
Map<String, String> toPointer() => <String, String>{
210-
'__type': 'Pointer',
211-
keyVarClassName: className,
212-
keyVarObjectId: objectId
213-
};
214208
}

lib/src/objects/parse_file.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ParseFile extends ParseObject {
3838
<String, String>{'__type': keyFile, 'name': name, 'url': url};
3939

4040
@override
41-
String toString() => json.encode(toString());
41+
String toString() => json.encode(toJson());
4242

4343
Future<ParseFile> loadStorage() async {
4444
final Directory tempPath = await getTemporaryDirectory();

lib/src/objects/parse_installation.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
part of flutter_parse_sdk;
22

33
class ParseInstallation extends ParseObject {
4-
54
/// Creates an instance of ParseInstallation
65
ParseInstallation(
76
{bool debug, ParseHTTPClient client, bool autoSendSessionId})
@@ -23,7 +22,8 @@ class ParseInstallation extends ParseObject {
2322

2423
Map<String, dynamic> get acl => super.get<Map<String, dynamic>>(keyVarAcl);
2524

26-
set acl(Map<String, dynamic> acl) => set<Map<String, dynamic>>(keyVarAcl, acl);
25+
set acl(Map<String, dynamic> acl) =>
26+
set<Map<String, dynamic>>(keyVarAcl, acl);
2727

2828
String get deviceToken => super.get<String>(keyDeviceToken);
2929

@@ -88,8 +88,7 @@ class ParseInstallation extends ParseObject {
8888
@override
8989
Future<ParseResponse> create() async {
9090
final bool isCurrent = await ParseInstallation.isCurrent(this);
91-
if (isCurrent)
92-
await _updateInstallation();
91+
if (isCurrent) await _updateInstallation();
9392
//ParseResponse parseResponse = await super.create();
9493
final ParseResponse parseResponse = await _create();
9594
if (parseResponse.success && isCurrent) {
@@ -119,7 +118,7 @@ class ParseInstallation extends ParseObject {
119118
(await ParseCoreData().getStore()).getString(keyParseStoreInstallation);
120119

121120
if (installationJson != null) {
122-
final dynamic installationMap = parseDecode(json.decode(installationJson));
121+
final dynamic installationMap = json.decode(installationJson);
123122

124123
if (installationMap != null) {
125124
return ParseInstallation()..fromJson(installationMap);
@@ -158,7 +157,8 @@ class ParseInstallation extends ParseObject {
158157
objectId = map['objectId'].toString();
159158
}
160159

161-
return handleResponse<ParseInstallation>(this, result, ParseApiRQ.create, _debug, className);
160+
return handleResponse<ParseInstallation>(
161+
this, result, ParseApiRQ.create, _debug, className);
162162
} on Exception catch (e) {
163163
return handleException(e, ParseApiRQ.create, _debug, className);
164164
}
@@ -178,7 +178,8 @@ class ParseInstallation extends ParseObject {
178178
ParseApiRQ.save.toString(), uri, body);
179179
}
180180
final Response result = await _client.put(uri, body: body);
181-
return handleResponse<ParseInstallation>(this, result, ParseApiRQ.save, _debug, className);
181+
return handleResponse<ParseInstallation>(
182+
this, result, ParseApiRQ.save, _debug, className);
182183
} on Exception catch (e) {
183184
return handleException(e, ParseApiRQ.save, _debug, className);
184185
}

lib/src/objects/parse_object.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class ParseObject extends ParseBase implements ParseCloneable {
7373
final Map<String, dynamic> map = json.decode(result.body);
7474
objectId = map['objectId'].toString();
7575
}
76-
7776
return handleResponse<ParseObject>(
7877
this, result, ParseApiRQ.create, _debug, className);
7978
} on Exception catch (e) {
@@ -281,4 +280,7 @@ class ParseObject extends ParseBase implements ParseCloneable {
281280
return handleException(e, ParseApiRQ.delete, _debug, className);
282281
}
283282
}
283+
284+
/// Converts the object to a Pointer to be used ONLY in queries using Pointers
285+
String toPointer() => json.encode(parseEncode(this));
284286
}

lib/src/utils/parse_encoder.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ dynamic parseEncode(dynamic value, {bool full}) {
2020
return _encodeDate(value);
2121
}
2222

23+
if (value is List) {
24+
return value.map((v) {
25+
return parseEncode(v);
26+
}).toList();
27+
}
28+
2329
if (value is ParseGeoPoint) {
2430
return value;
2531
}
@@ -32,7 +38,7 @@ dynamic parseEncode(dynamic value, {bool full}) {
3238
if (full) {
3339
return value.toJson(full: full);
3440
} else {
35-
return value.toPointer();
41+
return _encodeObject(value);
3642
}
3743
}
3844

@@ -44,5 +50,16 @@ Map<String, dynamic> _encodeUint8List(Uint8List value) {
4450
}
4551

4652
Map<String, dynamic> _encodeDate(DateTime date) {
47-
return <String, dynamic>{'__type': 'Date', 'iso': _parseDateFormat.format(date)};
53+
return <String, dynamic>{
54+
'__type': 'Date',
55+
'iso': _parseDateFormat.format(date)
56+
};
57+
}
58+
59+
Map<String, dynamic> _encodeObject(ParseObject object) {
60+
return {
61+
'__type': 'Pointer',
62+
keyVarClassName: object.className,
63+
keyVarObjectId: object.objectId
64+
};
4865
}

lib/src/utils/parse_utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ bool isDebugEnabled({bool providedDebugStatus}) {
1212
///
1313
/// Debug can be set in 2 places, one global param in the Parse.initialize, and
1414
/// then can be overwritten class by class
15-
ParseHTTPClient getDefaultHttpClient(ParseHTTPClient providedClient, bool sendSessionId) {
15+
ParseHTTPClient getDefaultHttpClient(
16+
ParseHTTPClient providedClient, bool sendSessionId) {
1617
return providedClient ??= ParseHTTPClient(
1718
sendSessionId: sendSessionId ?? ParseCoreData().autoSendSessionId,
1819
securityContext: ParseCoreData().securityContext);
@@ -24,9 +25,8 @@ ParseHTTPClient getDefaultHttpClient(ParseHTTPClient providedClient, bool sendSe
2425
dynamic convertValueToCorrectType(dynamic value) {
2526
if (value is String && !value.contains('__type')) {
2627
return '\"$value\"';
27-
}
28-
29-
if (value is DateTime || value is ParseObject) {
28+
}
29+
if (value is DateTime || value is ParseObject || value is ParseUser) {
3030
return parseEncode(value);
3131
} else {
3232
return value;

0 commit comments

Comments
 (0)