Used pagnation function from api helpers

Change-Id: I1bdd3608d3b46924b5da3ae282c99f85ee4e0dab
This commit is contained in:
Izaak Alpert 2013-09-24 09:22:46 -04:00
parent 9d06921ffb
commit 04c7c262a7
2 changed files with 6 additions and 8 deletions

View File

@ -497,5 +497,5 @@ GET /projects/search/:query
Parameters: Parameters:
+ query (required) - A string contained in the project name + query (required) - A string contained in the project name
+ per_page (optional) - number of projects to return per page, defaults to 20 + per_page (optional) - number of projects to return per page
+ offset (optional) - the offset in pages to retrieve + page (optional) - the page to retrieve

View File

@ -266,16 +266,14 @@ module API
# #
# Parameters: # Parameters:
# query (required) - A string contained in the project name # query (required) - A string contained in the project name
# per_page (optional) - number of projects to return per page, defaults to 20 # per_page (optional) - number of projects to return per page
# offset (optional) - the offset in pages to retrieve # page (optional) - the page to retrieve
# Example Request: # Example Request:
# GET /projects/search/:query # GET /projects/search/:query
get "/search/:query" do get "/search/:query" do
limit = (params[:per_page] || 20).to_i
offset = (params[:page] || 0).to_i * limit
ids = current_user.authorized_projects.map(&:id) ids = current_user.authorized_projects.map(&:id)
projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%").limit(limit).offset(offset) projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%")
present projects, with: Entities::Project present paginate(projects), with: Entities::Project
end end
end end
end end