motionbank / piecemaker2-api

An api at the core of piecemaker
7 stars 0 forks source link

Paging #85

Closed mattes closed 10 years ago

mattes commented 10 years ago

https://github.com/motionbank/piecemaker2-api/blob/master/api/event_groups.rb#L197

mattes commented 10 years ago

where else? @fjenett

fjenett commented 10 years ago

In the future i think we should add it here:

GET /api/v1/users.json
GET /api/v1/group/{id}/users.json
GET /api/v1/user/{id}/groups.json
GET /api/v1/groups.json
GET /api/v1/group/{id}/events.json

But for now it is most needed with the GET /api/v1/group/{id}/events.json call ...

mattes commented 10 years ago

Please read: https://dev.twitter.com/docs/working-with-timelines

So we could implement params like these:

      params do
        optional :count, type: Integer, desc: "Number of results to return"
        optional :since_id, type: Integer, desc: "Retrieve records after since_id"
      end 

Requests would look like:

# first request
GET /api/v1/users.json?count=2
  returns {result: [{id: 1, name: "peter"}, {id: 4, name: "pan"} ], more: true}

# more == true, so
# second request
GET /api/v1/users.json?count=2&since_id=4
  returns {result: [{id: 5, name: "klaus"}, {id: 6, name: "hans"} ], more: false}

not sure, if we need the max_id param.

This works for numeric IDs only. So it won't work for user_roles or role_permission. But I guess we won't need paging here.

what do you think, @fjenett ?

fjenett commented 10 years ago

Sounds good to me!

mattes commented 10 years ago
ASC
1
2
3
4
5

since_id: 2 => 3,4,5
max_id: 4 => 1,2,3

since_id: 2 && max_id: 4 => 3

DESC
5
4
3
2
1

since_id: 2 => 2
max_id: 4 => 5
since_id: 2 && max_id: 4 =>  nil

since_id: 4 => 3,2,1
max_id: 2 => 5,4,3
since_id: 4 && max_id: 2 => 3

Conclusion: Order by ID DESC will lead into issues!!!

Everything else works fine! ORDER BY user.name ASC or ORDER BY user.name DESC works i.e. as long as the ID is ordered by ASC.

mattes commented 10 years ago

Unlike max_id the since_id parameter is not inclusive

mattes commented 10 years ago

reference: http://sequel.jeremyevans.net/rdoc/files/doc/model_plugins_rdoc.html

mattes commented 10 years ago

see https://github.com/motionbank/piecemaker2-api/blob/e96c788a755bed91da974ee82c4eac4c93b766c3/lib/helper.rb#L25 for doc

mattes commented 10 years ago

Add params

      params do
        optional :count, type: Integer, default: 100, desc: "number of results"
        optional :max_id, type: Integer, desc: "return results to id"
        optional :since_id, type: Integer, desc: "return results from id"
      end

then in the logic:

User.page(params).all