Class: Correspondent::NotificationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Correspondent::NotificationsController
- Defined in:
- app/controllers/correspondent/notifications_controller.rb
Overview
NotificationsController
API for all notifications related endpoints.
Instance Method Summary collapse
-
#destroy ⇒ Object
destroy.
-
#dismiss ⇒ Object
dismiss.
-
#index ⇒ Object
index.
-
#preview ⇒ Object
preview.
Instance Method Details
#destroy ⇒ Object
destroy
Destroys a given notification.
49 50 51 52 |
# File 'app/controllers/correspondent/notifications_controller.rb', line 49 def destroy @notification&.destroy head(:no_content) end |
#dismiss ⇒ Object
dismiss
Dismisses a given notification.
41 42 43 44 |
# File 'app/controllers/correspondent/notifications_controller.rb', line 41 def dismiss @notification&.dismiss! head(:no_content) end |
#index ⇒ Object
index
Returns all notifications for a given subscriber.
16 17 18 19 |
# File 'app/controllers/correspondent/notifications_controller.rb', line 16 def index notifications = Correspondent::Notification.for_subscriber(params[:subscriber_type], params[:subscriber_id]) render(json: notifications) if stale?(notifications) end |
#preview ⇒ Object
preview
Returns the newest notification and the total number of notifications for the given subscriber.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/correspondent/notifications_controller.rb', line 25 def preview notifications = Correspondent::Notification.for_subscriber(params[:subscriber_type], params[:subscriber_id]) if stale?(notifications) render( json: { count: notifications.count, notification: notifications.limit(1).first } ) end end |