namespaces.rb 579 Bytes
Newer Older
1 2 3
module API
  # namespaces API
  class Namespaces < Grape::API
4
    before { authenticate! }
5 6

    resource :namespaces do
7 8 9 10 11 12
      desc 'Get a namespaces list' do
        success Entities::Namespace
      end
      params do
        optional :search, type: String, desc: "Search query for namespaces"
      end
13
      get do
14 15 16
        namespaces = current_user.admin ? Namespace.all : current_user.namespaces

        namespaces = namespaces.search(params[:search]) if params[:search].present?
17

18
        present paginate(namespaces), with: Entities::Namespace
19 20 21 22
      end
    end
  end
end