diff options
author | Jonne Haß <me@jhass.eu> | 2020-02-08 23:54:08 +0300 |
---|---|---|
committer | Jonne Haß <me@jhass.eu> | 2020-02-09 13:03:55 +0300 |
commit | 8068d8747b795d384f27e81a8f606af11a49f9c5 (patch) | |
tree | f05ecabee2f46f398c980ac821463a8a74b0ab5c /app | |
parent | cd0995abf34634b5f90ed7417863fb76c32f460c (diff) |
API: Fix fetching explicitly not only unread notifications
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/v1/notifications_controller.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/controllers/api/v1/notifications_controller.rb b/app/controllers/api/v1/notifications_controller.rb index 5fad84cfd..139f456c2 100644 --- a/app/controllers/api/v1/notifications_controller.rb +++ b/app/controllers/api/v1/notifications_controller.rb @@ -3,6 +3,8 @@ module Api module V1 class NotificationsController < Api::V1::BaseController + BOOLEAN_TYPE = ActiveModel::Type::Boolean.new + before_action do require_access_token %w[notifications] end @@ -24,25 +26,25 @@ module Api def index after_date = Date.iso8601(params[:only_after]) if params.has_key?(:only_after) - notifications_query = service.index(params[:only_unread], after_date) + 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, "Couldnt process the notifications requestt process the notifications request" + render_error 422, "Could not process the notifications request" end def update - read = ActiveModel::Type::Boolean.new.cast(params.require(:read)) + read = BOOLEAN_TYPE.cast(params.require(:read)) if service.update_status_by_guid(params[:id], read) head :no_content else - render_error 422, "Couldnt process the notifications requestt process the notifications request" + render_error 422, "Could not process the notifications request" end rescue ActionController::ParameterMissing - render_error 422, "Couldnt process the notifications requestt process the notifications request" + render_error 422, "Could not process the notifications request" end private |