namespaces.rb 642 Bytes
Newer Older
1 2
module API
  class Namespaces < Grape::API
3 4
    include PaginationParams

5
    before { authenticate! }
6 7

    resource :namespaces do
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"
13
        use :pagination
14
      end
15
      get do
16 17 18
        namespaces = current_user.admin ? Namespace.all : current_user.namespaces

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

20
        present paginate(namespaces), with: Entities::Namespace, current_user: current_user
21 22 23 24
      end
    end
  end
end