Class: Api::NotificationsController

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

Instance Method Summary collapse

Methods included from Response

#json_response

Instance Method Details

#all_readObject



25
26
27
28
# File 'app/controllers/api/notifications_controller.rb', line 25

def all_read
  @notifications.update_all(read: true)
  render json: { data: 'Notifications have been marked as read' }, status: :ok
end

#all_unreadObject



36
37
38
39
# File 'app/controllers/api/notifications_controller.rb', line 36

def all_unread
  @notifications.update_all(read: false)
  render json: { data: "All notifications have been marked as 'unread'" }, status: :ok
end

#indexObject



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

def index
  @pagy, @mynotifications = pagy(@notifications)
  render json: @mynotifications, status: :ok
end

#readObject



19
20
21
22
23
# File 'app/controllers/api/notifications_controller.rb', line 19

def read
  @notification.read = true
  @notification.save
  render json: { data: "Notification #{params[:id]} has been marked as read" }, status: :ok
end

#set_settingsObject



45
46
47
48
49
# File 'app/controllers/api/notifications_controller.rb', line 45

def set_settings
  raise ApiExceptions::UnprocessableEntity.new(message: 'Something went wrong') unless current_user.set_settings(params[:settings])

  render json: { data: 'Settings saved' }, status: :ok
end

#settingsObject



41
42
43
# File 'app/controllers/api/notifications_controller.rb', line 41

def settings
  render json: { settings: current_user.settings }, status: :ok
end

#showObject



15
16
17
# File 'app/controllers/api/notifications_controller.rb', line 15

def show
  render json: @notification, status: :ok
end

#unreadObject



30
31
32
33
34
# File 'app/controllers/api/notifications_controller.rb', line 30

def unread
  @notification.read = false
  @notification.save
  render json: { data: "Notification #{params[:id]} has marked as unread" }, status: :ok
end