diff options
author | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-03 04:46:29 -0700 |
---|---|---|
committer | Nihad Abbasov <narkoz.2008@gmail.com> | 2012-09-03 04:46:29 -0700 |
commit | 76e4d94d432b19d7dd58503c5eac46811630c04a (patch) | |
tree | 25d3df538ef33fcd3298672bfca8ef751e9fda22 /lib | |
parent | 6817a6a2952bc6af74eb239982ed337f90897f98 (diff) | |
download | gitlab-ce-76e4d94d432b19d7dd58503c5eac46811630c04a.tar.gz |
add pagination to API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/helpers.rb | 4 | ||||
-rw-r--r-- | lib/api/issues.rb | 4 | ||||
-rw-r--r-- | lib/api/milestones.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 2 | ||||
-rw-r--r-- | lib/api/users.rb | 2 |
5 files changed, 9 insertions, 5 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index c1ea05667ae..ce7b7b497fc 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -14,6 +14,10 @@ module Gitlab @project end + def paginate(object) + object.page(params[:page]).per(params[:per_page].to_i) + end + def authenticate! error!({'message' => '401 Unauthorized'}, 401) unless current_user end diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 836c2818544..68cb7e059b9 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -9,7 +9,7 @@ module Gitlab # Example Request: # GET /issues get do - present current_user.issues, with: Entities::Issue + present paginate(current_user.issues), with: Entities::Issue end end @@ -21,7 +21,7 @@ module Gitlab # Example Request: # GET /projects/:id/issues get ":id/issues" do - present user_project.issues, with: Entities::Issue + present paginate(user_project.issues), with: Entities::Issue end # Get a single project issue diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index f537b8e5bf2..29f5efa41d6 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -11,7 +11,7 @@ module Gitlab # Example Request: # GET /projects/:id/milestones get ":id/milestones" do - present user_project.milestones, with: Entities::Milestone + present paginate(user_project.milestones), with: Entities::Milestone end # Get a single project milestone diff --git a/lib/api/projects.rb b/lib/api/projects.rb index f42849cd2f2..3d4fde9270f 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -9,7 +9,7 @@ module Gitlab # Example Request: # GET /projects get do - @projects = current_user.projects + @projects = paginate current_user.projects present @projects, with: Entities::Project end diff --git a/lib/api/users.rb b/lib/api/users.rb index 81cb2a0e684..98ced6f8e5b 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -9,7 +9,7 @@ module Gitlab # Example Request: # GET /users get do - @users = User.all + @users = paginate User present @users, with: Entities::User end |