relationships_controller.rb 790 B

123456789101112131415161718192021222324
  1. # frozen_string_literal: true
  2. class Api::V1::Accounts::RelationshipsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:follows' }
  4. before_action :require_user!
  5. def index
  6. accounts = Account.without_suspended.where(id: account_ids).select('id')
  7. # .where doesn't guarantee that our results are in the same order
  8. # we requested them, so return the "right" order to the requestor.
  9. @accounts = accounts.index_by(&:id).values_at(*account_ids).compact
  10. render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: relationships
  11. end
  12. private
  13. def relationships
  14. AccountRelationshipsPresenter.new(@accounts, current_user.account_id)
  15. end
  16. def account_ids
  17. Array(params[:id]).map(&:to_i)
  18. end
  19. end