Sha256: a3ae92d94675c6651b61df408bcef948835453e6de96072c86e6b350cb44a43e

Contents?: true

Size: 1.68 KB

Versions: 16

Compression:

Stored size: 1.68 KB

Contents

class AlertsController < ApplicationController
  respond_to :json

  load_and_authorize_resource only: [:index, :show, :update, :destroy]
  wrap_parameters :alert, include: [:email, :query, :target, :comparator, :status, :description, :query_title, :query_id]

  def index
    respond_to do |format|
      format.html
      format.json do
        @paginated_alerts = Alert.paginated(@alerts, alert_pagination_params)
        render json: @paginated_alerts
      end
    end
  end

  def create
    respond_to do |format|
      format.json do
        alert = Alert.create(alert_params)

        if alert.errors.any?
          render json: alert.errors.full_messages, status: :unprocessable_entity
        else
          alert.run
          render json: alert, status: :created
        end
      end
    end
  end

  def update
    respond_to do |format|
      format.json do
        @alert.update_attributes!(alert_params)

        if @alert.errors.any?
          render json: @alert.errors.full_messages, status: :unprocessable_entity
        else
          @alert.run
          render json: @alert, status: :created
        end
      end
    end
  end

  def show
    respond_to do |format|
      format.json { render json: @alert }
      format.html { render template: 'application/index' }
    end
  end

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

  private

  def alert_params
    params.require(:alert).permit(:email, :query_id, :target, :comparator, :status, :description, :query_title)
  end

  def alert_pagination_params
    params.permit(:limit, :offset, :search, :sort_by, :sort_descending, :reset)
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev app/controllers/alerts_controller.rb
aleph_analytics-0.4.8 app/controllers/alerts_controller.rb
aleph_analytics-0.4.7 app/controllers/alerts_controller.rb
aleph_analytics-0.4.4 app/controllers/alerts_controller.rb
aleph_analytics-0.4.2 app/controllers/alerts_controller.rb
aleph_analytics-0.4.1 app/controllers/alerts_controller.rb
aleph_analytics-0.3.0 app/controllers/alerts_controller.rb
aleph_analytics-0.2.0 app/controllers/alerts_controller.rb
aleph_analytics-0.1.0 app/controllers/alerts_controller.rb
aleph_analytics-0.0.6 app/controllers/alerts_controller.rb
aleph_analytics-0.0.5 app/controllers/alerts_controller.rb
aleph_analytics-0.0.4 app/controllers/alerts_controller.rb
aleph_analytics-0.0.3 app/controllers/alerts_controller.rb
aleph_analytics-0.0.2 app/controllers/alerts_controller.rb
aleph_analytics-0.0.1.alpha app/controllers/alerts_controller.rb
aleph_analytics-0.0.0.alpha app/controllers/alerts_controller.rb