Class: Correspondent::NotificationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/correspondent/notifications_controller.rb

Overview

NotificationsController

API for all notifications related endpoints.

Instance Method Summary collapse

Instance Method Details

#destroyObject

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

#dismissObject

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

#indexObject

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

#previewObject

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