Add endpoints to accept and dismiss multiple notification requests at once (#31242)
This commit is contained in:
parent
584b1524dd
commit
da5b45a573
3 changed files with 54 additions and 1 deletions
|
@ -5,7 +5,8 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
|
|||
before_action -> { doorkeeper_authorize! :write, :'write:notifications' }, except: :index
|
||||
|
||||
before_action :require_user!
|
||||
before_action :set_request, except: :index
|
||||
before_action :set_request, only: [:show, :accept, :dismiss]
|
||||
before_action :set_requests, only: [:accept_bulk, :dismiss_bulk]
|
||||
|
||||
after_action :insert_pagination_headers, only: :index
|
||||
|
||||
|
@ -32,6 +33,16 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
|
|||
render_empty
|
||||
end
|
||||
|
||||
def accept_bulk
|
||||
@requests.each { |request| AcceptNotificationRequestService.new.call(request) }
|
||||
render_empty
|
||||
end
|
||||
|
||||
def dismiss_bulk
|
||||
@requests.each(&:destroy!)
|
||||
render_empty
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_requests
|
||||
|
@ -53,6 +64,10 @@ class Api::V1::Notifications::RequestsController < Api::BaseController
|
|||
@request = NotificationRequest.where(account: current_account).find(params[:id])
|
||||
end
|
||||
|
||||
def set_requests
|
||||
@requests = NotificationRequest.where(account: current_account, id: Array(params[:id]).uniq.map(&:to_i))
|
||||
end
|
||||
|
||||
def next_path
|
||||
api_v1_notifications_requests_url pagination_params(max_id: pagination_max_id) unless @requests.empty?
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue