Class: Motor::AlertsController
- Inherits:
-
ApiBaseController
- Object
- ActionController::API
- ApiBaseController
- Motor::AlertsController
- Defined in:
- app/controllers/motor/alerts_controller.rb
Instance Method Summary collapse
Methods included from CurrentAbility
Methods included from CurrentUserMethod
Instance Method Details
#create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/motor/alerts_controller.rb', line 20 def create if Motor::Alerts::Persistance.name_already_exists?(@alert) name_already_exists_response else ApplicationRecord.transaction { @alert.save! } Motor::Alerts::ScheduledAlertsCache.clear Motor::Configs::WriteToFile.call render json: { data: Motor::ApiQuery::BuildJson.call(@alert, params, current_ability) } end rescue Motor::Alerts::Persistance::InvalidInterval invalid_interval_response end |
#destroy ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/controllers/motor/alerts_controller.rb', line 46 def destroy @alert.update!(deleted_at: Time.current) Motor::Configs::WriteToFile.call head :ok end |
#index ⇒ Object
12 13 14 |
# File 'app/controllers/motor/alerts_controller.rb', line 12 def index render json: { data: Motor::ApiQuery::BuildJson.call(@alerts.active, params, current_ability) } end |
#show ⇒ Object
16 17 18 |
# File 'app/controllers/motor/alerts_controller.rb', line 16 def show render json: { data: Motor::ApiQuery::BuildJson.call(@alert, params, current_ability) } end |
#update ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/motor/alerts_controller.rb', line 34 def update Motor::Alerts::Persistance.update_from_params!(@alert, alert_params) Motor::Alerts::ScheduledAlertsCache.clear Motor::Configs::WriteToFile.call render json: { data: Motor::ApiQuery::BuildJson.call(@alert, params, current_ability) } rescue Motor::Alerts::Persistance::NameAlreadyExists name_already_exists_response rescue Motor::Alerts::Persistance::InvalidInterval invalid_interval_response end |