Search code examples
androidapiretrofitretrofit2loopback

Loopback remote method not returning correct values


I am used loopback's framework to generate my APIs. Now, I am trying to write a custom "RemoteMethod" that will require a long number (timestamp in unix format such as 1466598625506) and return an array of Sync Objects (I am using retrofit to comunicate with the endpoints). In my android app when I call the end point "getRecodsAfterTimestamp" it should return the records with equal or bigger timeStamp value than the provided one in the request. What It returns is all of the records (3 at this time).

This is how my model (sync.json) called Sync looks like:

{
"name": "Sync",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"uuid": {
  "type": "string"
},
"table": {
  "type": "string"
},
"action": {
  "type": "string"
},
"timeChanged": {
  "type": "number"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

And this is my sync.js with the remote method looks like:

module.exports = function(Sync) {

Sync.getRecodsAfterTimestamp = function(timestamp, cb){
// var response;

Sync.find({where:{ or: [
  {timeChanged:timestamp},
  {timeChanged: {gt:timestamp } }
] }}, function(err, sync) {
   cb(null,sync);
  // response.push(sync);
});

// cb(null, response);
}

Sync.remoteMethod (
'getRecodsAfterTimestamp',
{
  http: {path: '/getRecodsAfterTimestamp', verb: 'get'},
  accepts: {arg: 'timeChanged', type: 'number', http: { source: 'query' } },
  returns: {
    arg: 'data',
    type: 'array',
    root: true
  }
 }
);


};

I dont know if it matters but this is my retrofit method declaration:

@GET("Syncs")
Call<List<Sync>> getAllSyncsAfterThisTimeStamp(@Query(("getRecodsAfterTimestamp?timeChanged=")) long timeChanged);

And here I am calling it like that:

Long timeStamp = 1466598625506L;
Log.e(TAG, "Job Service task is running...");
getAllSyncsCall = espcService.getAllSyncsAfterThisTimeStamp(timeStamp);
getAllSyncsCall.enqueue(EspcJobSheculerService.this);

This code returns enter image description here

This is not the result I want. It should have returned all of the records after 1466598625506 which is two records only.


Solution

  • Your query is correct.

    Check in find callback you get right output or not