Sha256: 05d85a655c4aedebc4e38b7ce81ef60026a68d9a319251ae9496677325025022

Contents?: true

Size: 1.32 KB

Versions: 11

Compression:

Stored size: 1.32 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.html { render :index }
      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

11 entries across 11 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev app/controllers/results_controller.rb
aleph_analytics-0.4.8 app/controllers/results_controller.rb
aleph_analytics-0.4.7 app/controllers/results_controller.rb
aleph_analytics-0.4.4 app/controllers/results_controller.rb
aleph_analytics-0.4.2 app/controllers/results_controller.rb
aleph_analytics-0.4.1 app/controllers/results_controller.rb
aleph_analytics-0.3.0 app/controllers/results_controller.rb
aleph_analytics-0.2.0 app/controllers/results_controller.rb
aleph_analytics-0.1.0 app/controllers/results_controller.rb
aleph_analytics-0.0.6 app/controllers/results_controller.rb
aleph_analytics-0.0.5 app/controllers/results_controller.rb