2021-02-01 17:43:15 +01:00
|
|
|
# OpenAPI controller for the invoices
|
2016-05-04 18:17:50 +02:00
|
|
|
class OpenAPI::V1::InvoicesController < OpenAPI::V1::BaseController
|
2016-05-05 15:02:02 +02:00
|
|
|
extend OpenAPI::ApiDoc
|
|
|
|
expose_doc
|
|
|
|
|
2016-05-04 18:17:50 +02:00
|
|
|
def index
|
|
|
|
@invoices = Invoice.order(created_at: :desc)
|
|
|
|
|
2021-02-01 17:43:15 +01:00
|
|
|
@invoices = @invoices.where(user_id: params[:user_id]) if params[:user_id].present?
|
2016-05-04 18:17:50 +02:00
|
|
|
|
2021-02-01 17:43:15 +01:00
|
|
|
return unless params[:page].present?
|
|
|
|
|
|
|
|
@invoices = @invoices.page(params[:page]).per(per_page)
|
|
|
|
paginate @invoices, per_page: per_page
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def download
|
|
|
|
@invoice = Invoice.find(params[:id])
|
|
|
|
send_file File.join(Rails.root, @invoice.file), type: 'application/pdf', disposition: 'inline', filename: @invoice.filename
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2021-02-01 17:43:15 +01:00
|
|
|
|
|
|
|
def per_page
|
|
|
|
params[:per_page] || 20
|
|
|
|
end
|
2016-05-04 18:17:50 +02:00
|
|
|
end
|