Storing custom data in user profile ?

0 votes
Hello,

I am using cocos2d-x SDK with App42.

I want to save data linked with the User data.
The current documented solution is http://api.shephertz.com/app42-docs/user-management-service/#fetch-additional-data-of-user
But this is an extra query that can be expensive when requesting information on many users.

I want to have custom data associated with the user ( like the profile, but with my own format ).
How can I do this ?

I am currently experimenting by modifying the SDK to save extra data with the user, without success so far.

Thank you for the help.
asked Jul 22, 2014 in App42 Cloud API-BaaS by asmodehn (15 points)

1 Answer

0 votes

Hi,

We do have a method "AddUserInfo" in our latest released version 1.4 to associate custom data to the user. You can use it as follows:

const char* userName = "Nick";
const char* pwd = "*******";
const char* emailId = "nick@shephertz.co.in";
App42Object* app42Object = new App42Object();
app42Object->setObject("name", "John");
app42Object->setObject("age", "20");
const char* dbName = "<Enter_the_dbName>";
const char* collectionName = "<Your_Collection_Name>";
App42API::setDbName(dbName);
userService->AddUserInfo(object, collectionName);
userService->CreateUser(userName, pwd, emailId,this,app42callfuncND_selector(Sample_Class::onUserRequestCompleted));
To fetch the associated data you can use getUser API followed by setQuery method as follows:
 
const char* userName = "Nick";
const char* key = "name";
const char* value = "John";
Query* query = QueryBuilder::BuildQuery(key, value, APP42_OP_EQUALS);
const char* dbName = "<Enter_the_dbName>";
const char* collectionName = "<Your_Collection_Name>";
userService->setQuery(dbName,collectionName, query);
userService->GetUser(userName, this, app42callfuncND_selector(Sample_Class::onUserRequestCompleted));

We are in the process to update the docs for cocos2dx SDK, that will be done by tomorrow.

Let us know if you face any further problem.

Thanks

answered Jul 22, 2014 by rajeev.etc (1,660 points)
edited Jul 22, 2014 by rajeev.etc
I see... But that means every time I want to get information about a User, I have to run a query on a value of a key (in the storage service).

This sounds more costly than it needs to be...

Wouldn't it be better if I could just get the information directly from the profile ?

Or at least get the document ID from the profile, so that there is no need for a "search query" into the whole database ?

In my case I simply do not need the profile format as it is now, which is why I would like to change it...
The setQuery method is not an API call, it just sets values to the variables defined in App42API and App42Service classes that is local to the client. That values will be later used while making the requests you are going to make(i.e. CreateUser / GetUser) and it will not increase the number of API calls. In the above two cases, only CreateUser and GetUser will send requests to the server, so the total API count will be one in each case.

Let us know if you have any further query.
Understood.

But how can I save user data on an already existing User ?
I assume CreateUser() will fail if the user already exists, correct ?
To save user data to an existing user you can use createOrUpdateProfile API instead of using CreateUser API. To know more about createOrUpdateProfile, please go through the documentation ( http://api.shephertz.com/app42-docs/user-management-service/#create-user-profile ).

Let us know if you have any further query.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...