Commit 04c7c262a7be469a4ae4865464b003c4b522a895
1 parent
9d06921f
Exists in
master
and in
4 other branches
Used pagnation function from api helpers
Change-Id: I1bdd3608d3b46924b5da3ae282c99f85ee4e0dab
Showing
2 changed files
with
6 additions
and
8 deletions
Show diff stats
doc/api/projects.md
... | ... | @@ -497,5 +497,5 @@ GET /projects/search/:query |
497 | 497 | Parameters: |
498 | 498 | |
499 | 499 | + query (required) - A string contained in the project name |
500 | -+ per_page (optional) - number of projects to return per page, defaults to 20 | |
501 | -+ offset (optional) - the offset in pages to retrieve | |
500 | ++ per_page (optional) - number of projects to return per page | |
501 | ++ page (optional) - the page to retrieve | ... | ... |
lib/api/projects.rb
... | ... | @@ -266,16 +266,14 @@ module API |
266 | 266 | # |
267 | 267 | # Parameters: |
268 | 268 | # query (required) - A string contained in the project name |
269 | - # per_page (optional) - number of projects to return per page, defaults to 20 | |
270 | - # offset (optional) - the offset in pages to retrieve | |
269 | + # per_page (optional) - number of projects to return per page | |
270 | + # page (optional) - the page to retrieve | |
271 | 271 | # Example Request: |
272 | 272 | # GET /projects/search/:query |
273 | 273 | get "/search/:query" do |
274 | - limit = (params[:per_page] || 20).to_i | |
275 | - offset = (params[:page] || 0).to_i * limit | |
276 | 274 | ids = current_user.authorized_projects.map(&:id) |
277 | - projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%").limit(limit).offset(offset) | |
278 | - present projects, with: Entities::Project | |
275 | + projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%") | |
276 | + present paginate(projects), with: Entities::Project | |
279 | 277 | end |
280 | 278 | end |
281 | 279 | end | ... | ... |