Class: Comee::Core::NotificationsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#application_code, #authenticate, #current_application, #current_user, #render_content, #render_error, #skip_bullet

Methods included from Pagination

#default_per_page, #order_by, #order_direction, #page_no, #paginate, #paginate_offset, #per_page

Instance Method Details

#indexObject



6
7
8
9
# File 'app/controllers/comee/core/notifications_controller.rb', line 6

def index
  data = Notification.messages(current_user.notifications.newest_first)
  render_content(data)
end

#mark_as_readObject



21
22
23
24
# File 'app/controllers/comee/core/notifications_controller.rb', line 21

def mark_as_read
  @notification.mark_as_read!
  render json: {success: true, data: @notification.message}
end

#mark_as_unreadObject



26
27
28
29
# File 'app/controllers/comee/core/notifications_controller.rb', line 26

def mark_as_unread
  @notification.mark_as_unread!
  render json: {success: true, data: @notification.message}
end

#notifyObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/comee/core/notifications_controller.rb', line 31

def notify
  NotificationMailer.with(
    user: current_user,
    recipients: notify_params[:recipients],
    subject: notify_params[:subject],
    email_body: notify_params[:body],
    files: notify_params[:files]
  ).notify.deliver_now
  render json: {success: true}
rescue StandardError => e
  render_error(e)
end

#readObject



11
12
13
14
# File 'app/controllers/comee/core/notifications_controller.rb', line 11

def read
  data = Notification.messages(current_user.notifications.read.newest_first)
  render_content(data)
end

#unreadObject



16
17
18
19
# File 'app/controllers/comee/core/notifications_controller.rb', line 16

def unread
  data = Notification.messages(current_user.notifications.unread.newest_first)
  render_content(data)
end