fedibird-fe/app/controllers/api/v1/group_directories_controller.rb

25 lines
854 B
Ruby
Raw Normal View History

2020-07-15 15:07:13 +00:00
# frozen_string_literal: true
class Api::V1::GroupDirectoriesController < Api::BaseController
before_action :set_accounts
def show
render json: @accounts, each_serializer: REST::AccountSerializer
end
private
def set_accounts
@accounts = accounts_scope.offset(params[:offset]).limit(limit_param(DEFAULT_ACCOUNTS_LIMIT))
end
def accounts_scope
Account.discoverable.groups.tap do |scope|
scope.merge!(Account.by_recent_status) if params[:order].blank? || params[:order] == 'active'
scope.merge!(Account.order(id: :desc)) if params[:order] == 'new'
scope.merge!(Account.not_excluded_by_account(current_account)) if current_account
scope.merge!(Account.not_domain_blocked_by_account(current_account)) if current_account
end
end
end