Class: Api::NotificationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Api::NotificationsController
- Defined in:
- app/controllers/api/notifications_controller.rb
Instance Method Summary collapse
- #all_read ⇒ Object
- #all_unread ⇒ Object
- #index ⇒ Object
- #read ⇒ Object
- #set_settings ⇒ Object
- #settings ⇒ Object
- #show ⇒ Object
- #unread ⇒ Object
Methods included from Response
Instance Method Details
#all_read ⇒ Object
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_unread ⇒ Object
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 |
#index ⇒ Object
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 |
#read ⇒ Object
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_settings ⇒ Object
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 |
#settings ⇒ Object
41 42 43 |
# File 'app/controllers/api/notifications_controller.rb', line 41 def settings render json: { settings: current_user.settings }, status: :ok end |
#show ⇒ Object
15 16 17 |
# File 'app/controllers/api/notifications_controller.rb', line 15 def show render json: @notification, status: :ok end |
#unread ⇒ Object
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 |