1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/app/controllers/open_api/v1/subscriptions_controller.rb

36 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2023-03-06 16:35:50 +01:00
require_relative 'concerns/subscriptions_filters_concern'
# 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
include Rails::Pagination
2023-02-24 17:26:55 +01:00
include OpenAPI::V1::Concerns::SubscriptionsFiltersConcern
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)
@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