2017-03-21 21:32:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-07 14:09:25 -04:00
|
|
|
class Api::V1::SearchController < Api::BaseController
|
2017-07-15 09:42:24 -04:00
|
|
|
RESULTS_LIMIT = 10
|
2017-05-30 21:11:54 -04:00
|
|
|
|
2017-07-11 11:08:26 -04:00
|
|
|
before_action -> { doorkeeper_authorize! :read }
|
|
|
|
before_action :require_user!
|
|
|
|
|
2017-03-21 21:32:27 -04:00
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def index
|
2017-07-06 22:02:06 -04:00
|
|
|
@search = Search.new(search_results)
|
|
|
|
render json: @search, serializer: REST::SearchSerializer
|
2017-05-30 21:11:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def search_results
|
|
|
|
SearchService.new.call(
|
|
|
|
params[:q],
|
|
|
|
RESULTS_LIMIT,
|
|
|
|
resolving_search?,
|
|
|
|
current_account
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolving_search?
|
|
|
|
params[:resolve] == 'true'
|
2017-03-21 21:32:27 -04:00
|
|
|
end
|
|
|
|
end
|