summaryrefslogtreecommitdiff
path: root/lib/api/v3/groups.rb
blob: c826bc4fe0b2bb1c5f9c3bc3faa2b79f1e13acd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module API
  module V3
    class Groups < Grape::API
      include PaginationParams

      before { authenticate! }

      helpers do
        params :statistics_params do
          optional :statistics, type: Boolean, default: false, desc: 'Include project statistics'
        end

        def present_groups(groups, options = {})
          options = options.reverse_merge(
            with: ::API::Entities::Group,
            current_user: current_user,
          )

          groups = groups.with_statistics if options[:statistics]
          present paginate(groups), options
        end
      end

      resource :groups do
        desc 'Get list of owned groups for authenticated user' do
          success ::API::Entities::Group
        end
        params do
          use :pagination
          use :statistics_params
        end
        get '/owned' do
          present_groups current_user.owned_groups, statistics: params[:statistics]
        end
      end
    end
  end
end