Class: Api::V1::NotificationsController

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

Constant Summary collapse

BOOLEAN_TYPE =
ActiveModel::Type::Boolean.new

Instance Attribute Summary

Attributes included from OpenidConnect::ProtectedResourceEndpoint

#current_token

Instance Method Summary collapse

Methods included from OpenidConnect::ProtectedResourceEndpoint

#access_token?, #require_access_token

Instance Method Details

#indexObject


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/api/v1/notifications_controller.rb', line 26

def index
  after_date = Date.iso8601(params[:only_after]) if params.has_key?(:only_after)

  notifications_query = service.index(BOOLEAN_TYPE.cast(params[:only_unread]), after_date)
  notifications_page = time_pager(notifications_query).response
  notifications_page[:data] = notifications_page[:data].map do |note|
    NotificationPresenter.new(note, default_serializer_options).as_api_json
  end
  render_paged_api_response notifications_page
rescue ArgumentError
  render_error 422, "Could not process the notifications request"
end

#showObject


16
17
18
19
20
21
22
23
24
# File 'app/controllers/api/v1/notifications_controller.rb', line 16

def show
  notification = service.get_by_guid(params[:id])

  if notification
    render json: NotificationPresenter.new(notification).as_api_json
  else
    render_error 404, "Notification with provided guid could not be found"
  end
end

#updateObject


39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/api/v1/notifications_controller.rb', line 39

def update
  read = BOOLEAN_TYPE.cast(params.require(:read))
  if service.update_status_by_guid(params[:id], read)
    head :no_content
  else
    render_error 422, "Could not process the notifications request"
  end
rescue ActionController::ParameterMissing
  render_error 422, "Could not process the notifications request"
end