* API Articles v0-v1 restructure * Remove unused helper * Bulk move API controllers into concerns + add V1 controllers * Extract API routes + some fixes * Fix v1 api_controller authenticate! + add more article_controller specs * Completed spec/requests/api/v1/articles_spec.rb * specs up to listings * All v1 specs except for 9 skips * mime_types cleanup + authenticate! relocation Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
35 lines
824 B
Ruby
35 lines
824 B
Ruby
module Api
|
|
module FollowersController
|
|
extend ActiveSupport::Concern
|
|
|
|
include JsonApiSortParam
|
|
|
|
USERS_ATTRIBUTES_FOR_SERIALIZATION = %i[
|
|
id follower_id follower_type created_at
|
|
].freeze
|
|
private_constant :USERS_ATTRIBUTES_FOR_SERIALIZATION
|
|
|
|
def users
|
|
@follows = Follow.followable_user(@user.id)
|
|
.includes(:follower)
|
|
.select(USERS_ATTRIBUTES_FOR_SERIALIZATION)
|
|
.order(order_criteria)
|
|
.page(params[:page])
|
|
.per(@follows_limit)
|
|
end
|
|
|
|
private
|
|
|
|
def limit_per_page(default:, max:)
|
|
per_page = (params[:per_page] || default).to_i
|
|
@follows_limit = [per_page, max].min
|
|
end
|
|
|
|
def order_criteria
|
|
parse_sort_param(
|
|
allowed_fields: [:created_at],
|
|
default_sort: { created_at: :desc },
|
|
)
|
|
end
|
|
end
|
|
end
|