2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-15 08:24:10 -05:00
|
|
|
module API
|
|
|
|
class Namespaces < Grape::API
|
2016-12-04 12:11:19 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2015-05-25 16:51:37 -04:00
|
|
|
before { authenticate! }
|
2013-11-15 08:24:10 -05:00
|
|
|
|
|
|
|
resource :namespaces do
|
2016-09-13 14:55:26 -04:00
|
|
|
desc 'Get a namespaces list' do
|
|
|
|
success Entities::Namespace
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :search, type: String, desc: "Search query for namespaces"
|
2016-12-04 12:11:19 -05:00
|
|
|
use :pagination
|
2016-09-13 14:55:26 -04:00
|
|
|
end
|
2013-11-15 08:24:10 -05:00
|
|
|
get do
|
2016-09-13 14:55:26 -04:00
|
|
|
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
|
|
|
|
|
|
|
|
namespaces = namespaces.search(params[:search]) if params[:search].present?
|
2013-11-15 08:24:10 -05:00
|
|
|
|
2017-06-28 16:27:01 -04:00
|
|
|
present paginate(namespaces), with: Entities::Namespace, current_user: current_user
|
2013-11-15 08:24:10 -05:00
|
|
|
end
|
2017-11-16 20:43:55 -05:00
|
|
|
|
|
|
|
desc 'Get a namespace by ID' do
|
|
|
|
success Entities::Namespace
|
|
|
|
end
|
|
|
|
params do
|
2017-11-23 08:32:16 -05:00
|
|
|
requires :id, type: String, desc: "Namespace's ID or path"
|
2017-11-16 20:43:55 -05:00
|
|
|
end
|
|
|
|
get ':id' do
|
2017-11-23 08:32:16 -05:00
|
|
|
present user_namespace, with: Entities::Namespace, current_user: current_user
|
2017-11-16 20:43:55 -05:00
|
|
|
end
|
2013-11-15 08:24:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|