summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-09-25 06:57:34 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-09-25 06:57:34 -0700
commit1165759b14b02ad87dff46716e37e569f678b0b5 (patch)
tree8c3277a947e1c7094a0729748f8ec67522bd31d2 /lib/api/projects.rb
parent203bc7bb7e352391bc1405c800ae4907d7f3fe02 (diff)
parent04c7c262a7be469a4ae4865464b003c4b522a895 (diff)
downloadgitlab-ce-1165759b14b02ad87dff46716e37e569f678b0b5.tar.gz
Merge pull request #5146 from karlhungus/feature-api-search-for-projects-by-name
Added search for projects by name to api
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index c6ff524cb06..cf357b23c40 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -73,16 +73,16 @@ module API
post do
required_attributes! [:name]
attrs = attributes_for_keys [:name,
- :path,
- :description,
- :default_branch,
- :issues_enabled,
- :wall_enabled,
- :merge_requests_enabled,
- :wiki_enabled,
- :snippets_enabled,
- :namespace_id,
- :public]
+ :path,
+ :description,
+ :default_branch,
+ :issues_enabled,
+ :wall_enabled,
+ :merge_requests_enabled,
+ :wiki_enabled,
+ :snippets_enabled,
+ :namespace_id,
+ :public]
@project = ::Projects::CreateContext.new(current_user, attrs).execute
if @project.saved?
present @project, with: Entities::Project
@@ -113,14 +113,14 @@ module API
authenticated_as_admin!
user = User.find(params[:user_id])
attrs = attributes_for_keys [:name,
- :description,
- :default_branch,
- :issues_enabled,
- :wall_enabled,
- :merge_requests_enabled,
- :wiki_enabled,
- :snippets_enabled,
- :public]
+ :description,
+ :default_branch,
+ :issues_enabled,
+ :wall_enabled,
+ :merge_requests_enabled,
+ :wiki_enabled,
+ :snippets_enabled,
+ :public]
@project = ::Projects::CreateContext.new(user, attrs).execute
if @project.saved?
present @project, with: Entities::Project
@@ -165,7 +165,6 @@ module API
end
end
-
# Get a project team members
#
# Parameters:
@@ -262,6 +261,20 @@ module API
{message: "Access revoked", id: params[:user_id].to_i}
end
end
+
+ # search for projects current_user has access to
+ #
+ # Parameters:
+ # query (required) - A string contained in the project name
+ # per_page (optional) - number of projects to return per page
+ # page (optional) - the page to retrieve
+ # Example Request:
+ # GET /projects/search/:query
+ get "/search/:query" do
+ ids = current_user.authorized_projects.map(&:id)
+ projects = Project.where("(id in (?) OR public = true) AND (name LIKE (?))", ids, "%#{params[:query]}%")
+ present paginate(projects), with: Entities::Project
+ end
end
end
end