summaryrefslogtreecommitdiff
path: root/lib/api/project_statistics.rb
blob: 859e53b69816a4f59bf18023cf6b47e85ede7833 (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
# frozen_string_literal: true

module API
  class ProjectStatistics < ::API::Base
    feature_category :source_code_management

    before do
      authenticate!
      authorize! :daily_statistics, user_project
    end

    params do
      requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
    end
    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      desc 'Get the list of project fetch statistics for the last 30 days' do
        success Entities::ProjectDailyStatistics
        failure [
          { code: 404, message: '404 Project Not Found' },
          { code: 401, message: '401 Unauthorized' }
        ]
        tags %w[projects]
      end

      get ":id/statistics" do
        statistic_finder = ::Projects::DailyStatisticsFinder.new(user_project)

        present statistic_finder, with: Entities::ProjectDailyStatistics
      end
    end
  end
end