module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::AlertsController
Public Instance Methods
create()
click to toggle source
POST /jpi/v1/impac/kpis/:kpi_id/alerts
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 19 def create return render_bad_request('attach alert to kpi', 'no alert specified') unless params.require(:alert) return render_not_found('kpi') unless kpi_alert.kpi authorize! :update_impac_kpis, kpi_alert.kpi if (@alert = current_user.alerts.create(kpi_alert.attributes)) render 'show' else render_bad_request('attach alert to kpi', "impossible to save record: #{@kpi_alert.inspect}") end end
destroy()
click to toggle source
DELETE /jpi/v1/impac/alerts/:id
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 47 def destroy return render_not_found('alert') unless alert authorize! :update_impac_kpis, alert.kpi service = alert.service if alert.destroy render json: { deleted: { service: service } } else render_bad_request('destroy alert', "impossible to destroy record: #{alert.inspect}") end end
index()
click to toggle source
GET /jpi/v1/impac/alerts
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 14 def index @alerts = current_user.alerts end
update()
click to toggle source
PUT /jpi/v1/impac/alerts/:id
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 32 def update return render_bad_request('update alert attributes', 'no alert hash specified') unless params.require(:alert) return render_not_found('alert') unless alert authorize! :update_impac_kpis, alert.kpi attributes = params.require(:alert).permit(:title, :webhook, :sent) if alert.update(attributes) render 'show' else render_bad_request('update alert', "unable to save record: #{alert.inspect}") end end
Private Instance Methods
alert()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 62 def alert @alert ||= MnoEnterprise::Impac::Alert.find(params.require(:id)) end
kpi_alert()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/alerts_controller.rb, line 66 def kpi_alert @alert ||= ( kpi_id = params.require(:kpi_id) attributes = params.require(:alert).merge(impac_kpi_id: kpi_id) MnoEnterprise::Impac::Alert.new(attributes) ) end