2023-02-06 16:46:54 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
require_relative 'concerns/subscriptions_filters_concern'
|
|
|
|
|
2023-02-06 16:46:54 +01:00
|
|
|
# authorized 3rd party softwares can fetch the subscriptions through the OpenAPI
|
|
|
|
class OpenAPI::V1::SubscriptionsController < OpenAPI::V1::BaseController
|
2023-02-24 17:26:55 +01:00
|
|
|
extend OpenAPI::APIDoc
|
2023-02-06 16:46:54 +01:00
|
|
|
include Rails::Pagination
|
2023-02-24 17:26:55 +01:00
|
|
|
include OpenAPI::V1::Concerns::SubscriptionsFiltersConcern
|
2023-02-06 16:46:54 +01:00
|
|
|
expose_doc
|
|
|
|
|
|
|
|
def index
|
|
|
|
@subscriptions = Subscription.order(created_at: :desc)
|
|
|
|
.includes(:plan, statistic_profile: :user)
|
|
|
|
.references(:statistic_profile, :plan)
|
|
|
|
|
2023-03-06 16:35:50 +01:00
|
|
|
@subscriptions = filter_by_after(@subscriptions, params)
|
|
|
|
@subscriptions = filter_by_before(@subscriptions, params)
|
|
|
|
@subscriptions = filter_by_plan(@subscriptions, params)
|
|
|
|
@subscriptions = filter_by_user(@subscriptions, params)
|
2023-02-06 16:46:54 +01:00
|
|
|
|
|
|
|
@subscriptions = @subscriptions.page(page).per(per_page)
|
|
|
|
paginate @subscriptions, per_page: per_page
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def page
|
|
|
|
params[:page] || 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
|
|
|
end
|