Commit 04c7c262a7be469a4ae4865464b003c4b522a895

Authored by Izaak Alpert
1 parent 9d06921f

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,5 +497,5 @@ GET /projects/search/:query
497 Parameters: 497 Parameters:
498 498
499 + query (required) - A string contained in the project name 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,16 +266,14 @@ module API
266 # 266 #
267 # Parameters: 267 # Parameters:
268 # query (required) - A string contained in the project name 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 # Example Request: 271 # Example Request:
272 # GET /projects/search/:query 272 # GET /projects/search/:query
273 get "/search/:query" do 273 get "/search/:query" do
274 - limit = (params[:per_page] || 20).to_i  
275 - offset = (params[:page] || 0).to_i * limit  
276 ids = current_user.authorized_projects.map(&:id) 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 end 277 end
280 end 278 end
281 end 279 end