diff --git a/app/controllers/repp/v1/registrar/notifications_controller.rb b/app/controllers/repp/v1/registrar/notifications_controller.rb index 4e00a9321..1108d434e 100644 --- a/app/controllers/repp/v1/registrar/notifications_controller.rb +++ b/app/controllers/repp/v1/registrar/notifications_controller.rb @@ -18,6 +18,20 @@ module Repp render_success(data: data) 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]) + + render_success(data: data) + end + api :GET, '/repp/v1/registrar/notifications/:notification_id' desc 'Get a specific poll message' def show @@ -45,6 +59,18 @@ module Repp def set_notification @notification = current_user.unread_notifications.find(params[:id]) 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 diff --git a/config/routes.rb b/config/routes.rb index 4e78b7c0f..48186070b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -54,7 +54,11 @@ Rails.application.routes.draw do resources :auctions, only: %i[index] resources :retained_domains, only: %i[index] 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 collection do put '/', to: 'nameservers#update'