Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Increment field Example #92

Closed
aminediab opened this issue Mar 4, 2019 · 25 comments
Closed

Increment field Example #92

aminediab opened this issue Mar 4, 2019 · 25 comments

Comments

@aminediab
Copy link

aminediab commented Mar 4, 2019

hi all!
I am trying to test the increment option using the following code but have no luck, could anyone please indicate what I am doing wrong!
Thanks,

var apiResponse = await DietPlan()
.getObject('i1FgSlj5TJ');

if (apiResponse.success && apiResponse.result != null) {
  var dietPlan = apiResponse.result as DietPlan;
  dietPlan.increment('Carbs', 10);
  dietPlan.save();
}

@phillwiggins
Copy link
Member

phillwiggins commented Mar 4, 2019 via email

@aminediab
Copy link
Author

Hi Phill,
I tried it without the save option, still not updating the field, i am on back4app and able to verify it! no change. I understood that the increment marks the field for update, and running the save command commits the update! any thoughts, and by the way I thank you for your great efforts and support :)

@phillwiggins
Copy link
Member

It should just work server side when you increment. The increment method returns a Result object. Can you verify the result that is returned after calling increment?

I.e.

'var response = dietPlan.increment('Carbs', 10);'

@aminediab
Copy link
Author

OK the response is => (Instance of 'Future') with no returned object!
in debugging the variable it is shows a bunch of errors!

@phillwiggins
Copy link
Member

phillwiggins commented Mar 4, 2019 via email

@aminediab
Copy link
Author

Phill I don't see that you missed the await!

/// Increases a num of an object by x amount
Future increment(String key, num amount) async {
if (key != null) {
return await _increment(ParseApiRQ.increment, "Increment", key, amount);
} else {
return null;
}
}

@phillwiggins
Copy link
Member

Apologies, I meant my code example to you. I missed the await.

'var response = await dietPlan.increment('Carbs', 10);'

@aminediab
Copy link
Author

OK, now the response result is null, and i have a parse error: Unexpected End of Json Input

@phillwiggins
Copy link
Member

phillwiggins commented Mar 4, 2019 via email

@aminediab
Copy link
Author

Great, I have another question when deleting and object the two parameters are path and objectId. The path is the local storage path, when pinning an object, lets say i want to pin a diet plan object, what path do i use for deleting it in both online and local?

@aminediab
Copy link
Author

I did not realize it was that late in the evening! good night we'll pick it up tomorrow, thanks a lot

@phillwiggins
Copy link
Member

phillwiggins commented Mar 5, 2019 via email

@aminediab
Copy link
Author

Good Morning Phill,
Thank you for taking the time to fix the errors. I have another question, after successfully pinning a diet_plan object I tried to delete it online and locally, however I don't know what is the path that i should use, in this case used null! I can delete online but not locally, to test I used the following code as example, what is the path syntax?

void deleteDietPlanObject() async {
var apiResponse = await DietPlan().delete(null, 'i1FgSlj5TJ');
if (apiResponse.success && apiResponse.result != null) {
print(ApplicationConstants.keyAppName +
": " +
apiResponse.result.toString());
}

// test if pin exists
DietPlan newDietPlanFromPin = await DietPlan().fromPin('i1FgSlj5TJ');
if (newDietPlanFromPin != null) {
print(newDietPlanFromPin.get('Carbs'));
print('Retreiving from pin worked!');
} else {
print('Error');
}
}

@phillwiggins
Copy link
Member

phillwiggins commented Mar 5, 2019 via email

@RodrigoSMarques
Copy link
Contributor

@phillwiggins and @aminediab.

I found the reason for the error in increment and decrement. I'm completing the tests and I'm going to upload a PR.

The same solution will solve problems in addAll, addUnique and add in List.

I'll also add support for Pointer.

Same as increment and decrement and list operations, saving a Pointer must be done in two steps at creation.

First you must save the object and then use the result of the Response (as ParseObject) and perform the operations.

During creation ParseObject does not have the objectId, only the response it has. Then the response is used to perform the operations.

Sorry, I'm not fluent in English I'm using a translator for support.

@phillwiggins
Copy link
Member

phillwiggins commented Mar 7, 2019 via email

@aminediab
Copy link
Author

Thanks Rodrigo!

@aminediab
Copy link
Author

Phill/Rodrigo,

You all are doing a Great Job. I really believe, once most of the parse server functionality is implemented and tested, this Flutter Parse Server Package will surely be in the Top 10!

As a reminder, The increment and decrement still not working as of your latest git. Rodrigo mentioned he is going to fix it!

@RodrigoSMarques
Copy link
Contributor

Hi @aminediab,
I had changed and tested counters (increment and decrement).
I checked now that the changes did not go up to git. I am checking what happened and I will soon do a PR.

@RodrigoSMarques
Copy link
Contributor

Hi @aminediab.
Try again.

Update pubspec.yaml


dependencies:
flutter:
sdk: flutter
#parse_server_sdk: ^1.0.15
parse_server_sdk:
git: git://github.com/phillwiggins/flutter_parse_sdk.git


@aminediab
Copy link
Author

Hi Rodrigo,
I updated pubspec.yaml, the apiResponse.result returns the object successfuly. However, it failed on increment with error, parse error ! I also tried it with saving and without saving(last statement),

void incrementDietPlanProtein() async {
var apiResponse = await DietPlan().getObject('mqinMzhxJY');

if (apiResponse.success && apiResponse.result != null) {
  var myDiet = (apiResponse.result as DietPlan);
  var response = await myDiet.increment('Protein', 10);
  //myDiet.save();
}

}

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Mar 10, 2019

Hi @aminediab

You can verify that the file code "lib/src/objects/parse_object.dart" in your local repository contains these changes here: https://github.com/phillwiggins/flutter_parse_sdk/pull/107/files

You can check this using Go To -> Declaration in Android Studio or Go To Definition in Visual Code

You can verify that the change is the same for array operations. Function _sortArrays:
https://github.com/phillwiggins/flutter_parse_sdk/pull/102/files

If you wait a while, I've created the setIncrement and setDecrement methods to be used in conjunction with save (), same as library for Android / iOS.

For example:
` var parseObject = ParseObject ("TestAPI", debug: true);

    parseObject.setIncrement ("intNumber2", 2);

   parseObject.setDecrement ("intNumber3", 2);

   apiResponse = await parseObject.save ();
`
I am finalizing the tests and I must release today or tomorrow.

@RodrigoSMarques
Copy link
Contributor

Hi @aminediab

Did you take the test again? The new features are available in the latest release.

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented Mar 28, 2019

@phillwiggins
this issue can be closed.

Resolved in the last release.

Updated documentation.

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
Close this issue to keep open only what is in trouble.
Resolved in previous releases. It is inactive because it has not received any new comments.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants