You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
711 B

  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