2014-09-02 18:07:02 +05:30
|
|
|
module API
|
|
|
|
class Namespaces < Grape::API
|
2017-08-17 22:00:37 +05:30
|
|
|
include PaginationParams
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before { authenticate! }
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
resource :namespaces do
|
2016-11-03 12:29:30 +05:30
|
|
|
desc 'Get a namespaces list' do
|
|
|
|
success Entities::Namespace
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :search, type: String, desc: "Search query for namespaces"
|
2017-08-17 22:00:37 +05:30
|
|
|
use :pagination
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
get do
|
2016-11-03 12:29:30 +05:30
|
|
|
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
|
|
|
|
|
|
|
|
namespaces = namespaces.search(params[:search]) if params[:search].present?
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
present paginate(namespaces), with: Entities::Namespace
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|