queries_controller.rb 646 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class Api::V1::Crypto::Keys::QueriesController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :crypto }
  4. before_action :require_user!
  5. before_action :set_accounts
  6. before_action :set_query_results
  7. def create
  8. render json: @query_results, each_serializer: REST::Keys::QueryResultSerializer
  9. end
  10. private
  11. def set_accounts
  12. @accounts = Account.where(id: account_ids).includes(:devices)
  13. end
  14. def set_query_results
  15. @query_results = @accounts.filter_map { |account| ::Keys::QueryService.new.call(account) }
  16. end
  17. def account_ids
  18. Array(params[:id]).map(&:to_i)
  19. end
  20. end