relationships_controller.rb 779 B

1234567891011121314151617181920212223
  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, :domain).to_a
  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. render json: @accounts.index_by(&:id).values_at(*account_ids).compact, each_serializer: REST::RelationshipSerializer, relationships: relationships
  10. end
  11. private
  12. def relationships
  13. AccountRelationshipsPresenter.new(@accounts, current_user.account_id)
  14. end
  15. def account_ids
  16. Array(params[:id]).map(&:to_i)
  17. end
  18. end