Sha256: eeec4dff967a9083a52b13126ac7fd79b9a84924f0ac67ab9b5f31d04d6756c8

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

module ForemanStatistics
  module Api
    module V2
      class TrendsController < ::Api::V2::BaseController
        include ForemanStatistics::Parameters::Trend

        before_action :find_resource, :only => %i[show destroy]

        TRENDABLE_TYPES = %w[
          Environment Operatingsystem Model FactName Hostgroup
          ComputeResource
        ].freeze

        resource_description do
          api_version 'v2'
          api_base_url '/foreman_statistics/api'
        end

        api :GET, '/trends/', N_('List of trends counters')
        def index
          @trends = resource_scope_for_index
        end

        api :GET, '/trends/:id/', N_('Show a trend')
        param :id, :identifier, :required => true
        def show; end

        api :POST, '/trends/', N_('Create a trend counter')
        param :trendable_type, TRENDABLE_TYPES, :required => true
        param :fact_name, String, :required => false
        param :name, String, :required => false
        def create
          @trend = ForemanStatistics::Trend.build_trend(trend_params)
          if @trend.save
            process_success
          else
            process_resource_error
          end
        end

        api :DELETE, '/trends/:id/', N_('Delete a trend counter')
        param :id, :identifier, :required => true
        def destroy
          process_response @trend.destroy
        end

        # Overload this method to avoid using search_for method
        def resource_scope_for_index(options = {})
          resource_scope(options).paginate(paginate_options)
        end

        def resource_scope(options = {})
          @resource_scope ||= scope_for(ForemanStatistics::Trend.types, options)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_statistics-0.1.1 app/controllers/foreman_statistics/api/v2/trends_controller.rb
foreman_statistics-0.1.0 app/controllers/foreman_statistics/api/v2/trends_controller.rb