mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
Merge pull request #1936 from internetee/1869-repp-list-access-to-poll-messages
implement get all list notifications repp endpoint
This commit is contained in:
commit
ca06ae6414
3 changed files with 46 additions and 1 deletions
|
@ -18,6 +18,24 @@ module Repp
|
||||||
render_success(data: data)
|
render_success(data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api :GET, '/repp/v1/registrar/notifications/all_notifications'
|
||||||
|
desc 'Get the all unread poll messages'
|
||||||
|
def all_notifications
|
||||||
|
records = current_user.unread_notifications.order('created_at DESC').all
|
||||||
|
|
||||||
|
@notification = records.limit(limit).offset(offset)
|
||||||
|
# rubocop:disable Style/AndOr
|
||||||
|
render_success(data: nil) and return unless @notification
|
||||||
|
# rubocop:enable Style/AndOr
|
||||||
|
|
||||||
|
data = @notification.as_json(only: %i[id text attached_obj_id attached_obj_type])
|
||||||
|
|
||||||
|
message = 'Command completed successfully.'\
|
||||||
|
" Returning #{@notification.count} out of #{records.count}."\
|
||||||
|
' Use URL parameters :limit and :offset to list other messages if needed.'
|
||||||
|
render_success(data: data, message: message)
|
||||||
|
end
|
||||||
|
|
||||||
api :GET, '/repp/v1/registrar/notifications/:notification_id'
|
api :GET, '/repp/v1/registrar/notifications/:notification_id'
|
||||||
desc 'Get a specific poll message'
|
desc 'Get a specific poll message'
|
||||||
def show
|
def show
|
||||||
|
@ -45,6 +63,18 @@ module Repp
|
||||||
def set_notification
|
def set_notification
|
||||||
@notification = current_user.unread_notifications.find(params[:id])
|
@notification = current_user.unread_notifications.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def limit
|
||||||
|
index_params[:limit] || 200
|
||||||
|
end
|
||||||
|
|
||||||
|
def offset
|
||||||
|
index_params[:offset] || 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def index_params
|
||||||
|
params.permit(:limit, :offset)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,11 @@ Rails.application.routes.draw do
|
||||||
resources :auctions, only: %i[index]
|
resources :auctions, only: %i[index]
|
||||||
resources :retained_domains, only: %i[index]
|
resources :retained_domains, only: %i[index]
|
||||||
namespace :registrar do
|
namespace :registrar do
|
||||||
resources :notifications, only: [:index, :show, :update]
|
resources :notifications, only: [:index, :show, :update] do
|
||||||
|
collection do
|
||||||
|
get '/all_notifications', to: 'notifications#all_notifications'
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :nameservers do
|
resources :nameservers do
|
||||||
collection do
|
collection do
|
||||||
put '/', to: 'nameservers#update'
|
put '/', to: 'nameservers#update'
|
||||||
|
|
|
@ -9,6 +9,17 @@ class ReppV1RegistrarNotificationsTest < ActionDispatch::IntegrationTest
|
||||||
@auth_headers = { 'Authorization' => token }
|
@auth_headers = { 'Authorization' => token }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_all_unreaded_poll_messages
|
||||||
|
notification = @user.registrar.notifications.where(read: false).order(created_at: :desc).all
|
||||||
|
get "/repp/v1/registrar/notifications/all_notifications", headers: @auth_headers
|
||||||
|
json = JSON.parse(response.body, symbolize_names: true)
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
assert_equal notification.count, json[:data].count
|
||||||
|
assert_equal json[:data].first[:text], notification.first.text
|
||||||
|
assert_equal json[:data].last[:text], notification.last.text
|
||||||
|
end
|
||||||
|
|
||||||
def test_gets_latest_unread_poll_message
|
def test_gets_latest_unread_poll_message
|
||||||
notification = @user.registrar.notifications.where(read: false).order(created_at: :desc).first
|
notification = @user.registrar.notifications.where(read: false).order(created_at: :desc).first
|
||||||
get "/repp/v1/registrar/notifications", headers: @auth_headers
|
get "/repp/v1/registrar/notifications", headers: @auth_headers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue