Sha256: 8e5f65793d37e4e450b6111a27254015e554d6dd33a358dc0f7405828d036fdc

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module Api
  module V1
    class ReportsController < V1::BaseController
      before_filter :find_resource, :only => %w{show update destroy}
      before_filter :setup_search_options, :only => [:index, :last]

      api :GET, "/reports/", "List all reports."
      param :search, String, :desc => "filter results"
      param :order, String, :desc => "sort results"
      param :page, String, :desc => "paginate results"
      param :per_page, String, :desc => "number of entries per request"

      def index
        @reports = Report.my_reports.includes(:logs => [:source, :message]).
          search_for(*search_options).paginate(paginate_options)
      end

      api :GET, "/reports/:id/", "Show a report."
      param :id, :identifier, :required => true

      def show
      end

      api :DELETE, "/ptables/:id/", "Delete a report."
      param :id, String, :required => true

      def destroy
        process_response @report.destroy
      end

      api :GET, "/hosts/:host_id/reports/last", "Show the last report for a given host."
      param :id, :identifier, :required => true

      def last
        conditions = { :host_id => Host.find_by_name(params[:host_id]).try(:id) } unless params[:host_id].blank?
        max_id = Report.my_reports.maximum(:id, :conditions => conditions)
        @report = Report.find(max_id, :include => { :logs => [:message, :source] })
        render :show
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/app/controllers/api/v1/reports_controller.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/app/controllers/api/v1/reports_controller.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/app/controllers/api/v1/reports_controller.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/app/controllers/api/v1/reports_controller.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/app/controllers/api/v1/reports_controller.rb