1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/app/controllers/open_api/v1/accounting_controller.rb
2022-12-21 14:11:39 +01:00

28 lines
714 B
Ruby

# frozen_string_literal: true
# OpenAPI controller for the accounting lines
class OpenAPI::V1::AccountingController < OpenAPI::V1::BaseController
extend OpenAPI::ApiDoc
include Rails::Pagination
expose_doc
def index
@invoices = Invoice.order(created_at: :desc)
.includes(invoicing_profile: :user)
.references(:invoicing_profiles)
@invoices = @invoices.where(invoicing_profiles: { user_id: params[:user_id] }) if params[:user_id].present?
return if params[:page].blank?
@invoices = @invoices.page(params[:page]).per(per_page)
paginate @invoices, per_page: per_page
end
private
def per_page
params[:per_page] || 20
end
end