Class: NotificationEngine::NotificationsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject

DELETE /notifications/:id



45
46
47
48
49
50
51
52
# File 'app/controllers/notification_engine/notifications_controller.rb', line 45

def destroy
  @notification.destroy

  respond_to do |format|
    format.turbo_stream
    format.html { redirect_to notifications_path, notice: "Notification removed." }
  end
end

#indexObject

GET /notifications GET /notifications?filter=unread GET /notifications?filter=read



10
11
12
# File 'app/controllers/notification_engine/notifications_controller.rb', line 10

def index
  @notifications = filtered_notifications
end

#mark_all_readObject

POST /notifications/mark_all_read



35
36
37
38
39
40
41
42
# File 'app/controllers/notification_engine/notifications_controller.rb', line 35

def mark_all_read
  notifications_scope.unread.mark_as_read

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.replace("notifications", partial: "notification_engine/notifications/list", locals: { notifications: filtered_notifications }) }
    format.html { redirect_to notifications_path, notice: "All notifications marked as read." }
  end
end

#mark_as_readObject

PATCH /notifications/:id/mark_as_read



15
16
17
18
19
20
21
22
# File 'app/controllers/notification_engine/notifications_controller.rb', line 15

def mark_as_read
  @notification.mark_as_read!

  respond_to do |format|
    format.turbo_stream
    format.html { redirect_to notifications_path, notice: "Notification marked as read." }
  end
end

#mark_as_unreadObject

PATCH /notifications/:id/mark_as_unread



25
26
27
28
29
30
31
32
# File 'app/controllers/notification_engine/notifications_controller.rb', line 25

def mark_as_unread
  @notification.mark_as_unread!

  respond_to do |format|
    format.turbo_stream
    format.html { redirect_to notifications_path, notice: "Notification marked as unread." }
  end
end