mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-11 21:56:13 +01:00
Remove deprecated GET /api/v1/search
API (#11823)
Use `GET /api/v2/search` instead
This commit is contained in:
parent
cf2b708e6b
commit
18331fefa2
@ -1,32 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class Api::V1::SearchController < Api::BaseController
|
|
||||||
include Authorization
|
|
||||||
|
|
||||||
RESULTS_LIMIT = 20
|
|
||||||
|
|
||||||
before_action -> { doorkeeper_authorize! :read, :'read:search' }
|
|
||||||
before_action :require_user!
|
|
||||||
|
|
||||||
respond_to :json
|
|
||||||
|
|
||||||
def index
|
|
||||||
@search = Search.new(search_results)
|
|
||||||
render json: @search, serializer: REST::SearchSerializer
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def search_results
|
|
||||||
SearchService.new.call(
|
|
||||||
params[:q],
|
|
||||||
current_account,
|
|
||||||
limit_param(RESULTS_LIMIT),
|
|
||||||
search_params.merge(resolve: truthy_param?(:resolve))
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
def search_params
|
|
||||||
params.permit(:type, :offset, :min_id, :max_id, :account_id)
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,8 +1,32 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Api::V2::SearchController < Api::V1::SearchController
|
class Api::V2::SearchController < Api::BaseController
|
||||||
|
include Authorization
|
||||||
|
|
||||||
|
RESULTS_LIMIT = 20
|
||||||
|
|
||||||
|
before_action -> { doorkeeper_authorize! :read, :'read:search' }
|
||||||
|
before_action :require_user!
|
||||||
|
|
||||||
|
respond_to :json
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@search = Search.new(search_results)
|
@search = Search.new(search_results)
|
||||||
render json: @search, serializer: REST::V2::SearchSerializer
|
render json: @search, serializer: REST::SearchSerializer
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_results
|
||||||
|
SearchService.new.call(
|
||||||
|
params[:q],
|
||||||
|
current_account,
|
||||||
|
limit_param(RESULTS_LIMIT),
|
||||||
|
search_params.merge(resolve: truthy_param?(:resolve))
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:type, :offset, :min_id, :max_id, :account_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class REST::SearchSerializer < ActiveModel::Serializer
|
class REST::SearchSerializer < ActiveModel::Serializer
|
||||||
attributes :hashtags
|
|
||||||
|
|
||||||
has_many :accounts, serializer: REST::AccountSerializer
|
has_many :accounts, serializer: REST::AccountSerializer
|
||||||
has_many :statuses, serializer: REST::StatusSerializer
|
has_many :statuses, serializer: REST::StatusSerializer
|
||||||
|
has_many :hashtags, serializer: REST::TagSerializer
|
||||||
def hashtags
|
|
||||||
object.hashtags.map(&:name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class REST::V2::SearchSerializer < ActiveModel::Serializer
|
|
||||||
has_many :accounts, serializer: REST::AccountSerializer
|
|
||||||
has_many :statuses, serializer: REST::StatusSerializer
|
|
||||||
has_many :hashtags, serializer: REST::TagSerializer
|
|
||||||
end
|
|
@ -311,8 +311,6 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/search', to: 'search#index', as: :search
|
|
||||||
|
|
||||||
resources :media, only: [:create, :update]
|
resources :media, only: [:create, :update]
|
||||||
resources :blocks, only: [:index]
|
resources :blocks, only: [:index]
|
||||||
resources :mutes, only: [:index]
|
resources :mutes, only: [:index]
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require 'rails_helper'
|
|
||||||
|
|
||||||
RSpec.describe Api::V1::SearchController, type: :controller do
|
|
||||||
render_views
|
|
||||||
|
|
||||||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
|
|
||||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:search') }
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(controller).to receive(:doorkeeper_token) { token }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'GET #index' do
|
|
||||||
it 'returns http success' do
|
|
||||||
get :index, params: { q: 'test' }
|
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user