Browse Source

Define a serializer for /api/v1/mutes/details

closed-social-glitch-2
Surinna Curtis 7 years ago
parent
commit
af2d793398
2 changed files with 21 additions and 2 deletions
  1. +6
    -2
      app/controllers/api/v1/mutes_controller.rb
  2. +15
    -0
      app/serializers/rest/mute_serializer.rb

+ 6
- 2
app/controllers/api/v1/mutes_controller.rb View File

@ -13,8 +13,8 @@ class Api::V1::MutesController < Api::BaseController
end
def details
@data = @mutes = paginated_mutes
render json: @mutes
@data = @mutes = load_mutes
render json: @mutes, each_serializer: REST::MuteSerializer
end
private
@ -27,6 +27,10 @@ class Api::V1::MutesController < Api::BaseController
Account.includes(:muted_by).references(:muted_by)
end
def load_mutes
paginated_mutes.includes(:account, :target_account).to_a
end
def paginated_mutes
Mute.where(account: current_account).paginate_by_max_id(
limit_param(DEFAULT_ACCOUNTS_LIMIT),

+ 15
- 0
app/serializers/rest/mute_serializer.rb View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
class REST::MuteSerializer < ActiveModel::Serializer
include RoutingHelper
attributes :id, :account, :target_account, :created_at, :hide_notifications
def account
REST::AccountSerializer.new(object.account)
end
def target_account
REST::AccountSerializer.new(object.target_account)
end
end

Loading…
Cancel
Save