androidretrofitretrofit2

How to apply filter to retrofit request?


In my server I have a table called Sync which looks like that:

}  
"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 in my database I have the following records in this table:

Sync": {
  "34": "{\"uuid\":\"287c6625-4a95-4e11-847e-ad13e98c75a2\",\"table\":\"Property\",\"action\":\"create\",\"timeChanged\":1466598611995,\"id\":34}",
  "35": "{\"uuid\":\"287c6625-4a95-4e11-847e-ad13e98c75a2\",\"table\":\"Property\",\"action\":\"update\",\"timeChanged\":1466598625506,\"id\":35}",
  "36": "{\"uuid\":\"176aa537-d000-496a-895c-315f608ce494\",\"table\":\"Property\",\"action\":\"update\",\"timeChanged\":1466598649119,\"id\":36}"
}

How to apply a filter to by @GET request and I get all of the records say with timeChanged attribute bigger than or equal to "1466598625506".

I did try that:

    @GET("Syncs")
Call<List<Sync>> getAllSyncsAfterThisTimeStamp(@Query(("filter[where][timeChanged]=>")) long timeChanged);

but that returns an empty array "[]". Please, any ideas how to get this filtering done?


Solution

  • There can be solution to this on the server side. I don't think that retrofit alone will be able to accomplish this task. You can write a logic on server side which takes a get argument as a number and returns all object greater than or equal to that number. Corresponding to this server script, you can make requests where you can pass a query parameter and get the desired result. You cant run a database query from a get or post request.