0
0
Fork 0

Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090)

This commit is contained in:
Eugen Rochko 2017-07-07 04:02:06 +02:00 committed by GitHub
parent 2d6128672f
commit 8b2cad5637
80 changed files with 425 additions and 301 deletions

View file

@ -6,13 +6,13 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
def show
@account = current_account
render 'api/v1/accounts/show'
render json: @account, serializer: REST::AccountSerializer
end
def update
current_account.update!(account_params)
@account = current_account
render 'api/v1/accounts/show'
render json: @account, serializer: REST::AccountSerializer
end
private

View file

@ -9,7 +9,7 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController
def index
@accounts = load_accounts
render 'api/v1/accounts/index'
render json: @accounts, each_serializer: REST::AccountSerializer
end
private

View file

@ -9,7 +9,7 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController
def index
@accounts = load_accounts
render 'api/v1/accounts/index'
render json: @accounts, each_serializer: REST::AccountSerializer
end
private

View file

@ -8,16 +8,15 @@ class Api::V1::Accounts::RelationshipsController < Api::BaseController
def index
@accounts = Account.where(id: account_ids).select('id')
@following = Account.following_map(account_ids, current_user.account_id)
@followed_by = Account.followed_by_map(account_ids, current_user.account_id)
@blocking = Account.blocking_map(account_ids, current_user.account_id)
@muting = Account.muting_map(account_ids, current_user.account_id)
@requested = Account.requested_map(account_ids, current_user.account_id)
@domain_blocking = Account.domain_blocking_map(account_ids, current_user.account_id)
render json: @accounts, each_serializer: REST::RelationshipSerializer, relationships: relationships
end
private
def relationships
AccountRelationshipsPresenter.new(@accounts, current_user.account_id)
end
def account_ids
@_account_ids ||= Array(params[:id]).map(&:to_i)
end

View file

@ -8,8 +8,7 @@ class Api::V1::Accounts::SearchController < Api::BaseController
def show
@accounts = account_search
render 'api/v1/accounts/index'
render json: @accounts, each_serializer: REST::AccountSerializer
end
private

View file

@ -9,6 +9,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
def index
@statuses = load_statuses
render json: @statuses, each_serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new(@statuses, current_user&.account_id)
end
private
@ -18,9 +19,7 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
end
def load_statuses
cached_account_statuses.tap do |statuses|
set_maps(statuses)
end
cached_account_statuses
end
def cached_account_statuses