Sha256: d0ca5e296c32f0623c2c7dcb9c9bbad441a600aceda4160bf1511199f18f16ff

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

class ResultsController < ApplicationController
  include QueryVersionSupport

  respond_to :json, :html
  load_and_authorize_resource only: [:show, :destroy]
  before_filter :retrieve_query_version, if: -> { params[:query_id] }, only: [:index]

  def index
    respond_to do |format|
      format.html
      format.json do
        @results = @query_version.results.accessible_by(current_ability)
        render json: @results
      end
    end
  end

  def show
    respond_to do |format|
      format.json { render json: @result }
    end
  end

  def destroy
    respond_to do |format|
      format.json do
        @result.destroy!
        render json: @result
      end
    end
  end

  def create
    interaction = Interaction::ResultCreation.new(result_params)
    result = interaction.execute

    if interaction.errors.any?
      render json: interaction.errors, status: :unprocessable_entity
    else
      Resque.enqueue(QueryExecution, result.id, current_user.role)
      render json: result, status: :created
    end
  end

  private

  def result_params
    params.permit(:body, :query_version_id, :query_id).tap do |whitelisted|
      whitelisted[:substitution_values] = params[:substitution_values]
      whitelisted[:parameters] = params[:parameters]
    end.merge(owner: current_user)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aleph_analytics-0.0.4 app/controllers/results_controller.rb
aleph_analytics-0.0.3 app/controllers/results_controller.rb
aleph_analytics-0.0.2 app/controllers/results_controller.rb
aleph_analytics-0.0.1.alpha app/controllers/results_controller.rb
aleph_analytics-0.0.0.alpha app/controllers/results_controller.rb