search_controller.rb 711 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V2::SearchController < Api::BaseController
  3. include Authorization
  4. RESULTS_LIMIT = 20
  5. before_action -> { doorkeeper_authorize! :read, :'read:search' }
  6. before_action :require_user!
  7. def index
  8. @search = Search.new(search_results)
  9. render json: @search, serializer: REST::SearchSerializer
  10. end
  11. private
  12. def search_results
  13. SearchService.new.call(
  14. params[:q],
  15. current_account,
  16. limit_param(RESULTS_LIMIT),
  17. search_params.merge(resolve: truthy_param?(:resolve), exclude_unreviewed: truthy_param?(:exclude_unreviewed))
  18. )
  19. end
  20. def search_params
  21. params.permit(:type, :offset, :min_id, :max_id, :account_id)
  22. end
  23. end