BigW Consortium Gitlab

namespaces.rb 935 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
      end
22 23 24 25 26

      desc 'Get a namespace by ID' do
        success Entities::Namespace
      end
      params do
27
        requires :id, type: String, desc: "Namespace's ID or path"
28 29
      end
      get ':id' do
30
        present user_namespace, with: Entities::Namespace, current_user: current_user
31
      end
32 33 34
    end
  end
end