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

33 lines
900 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# 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
include Rails::Pagination
2016-05-05 15:02:02 +02:00
expose_doc
2016-05-04 18:17:50 +02:00
def index
@invoices = Invoice.order(created_at: :desc)
.includes(invoicing_profile: :user)
.references(:invoicing_profiles)
2016-05-04 18:17:50 +02:00
@invoices = @invoices.where(invoicing_profiles: { user_id: may_array(params[:user_id]) }) if params[:user_id].present?
2016-05-04 18:17:50 +02:00
return if params[:page].blank?
@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 Rails.root.join(@invoice.file), type: 'application/pdf', disposition: 'inline', filename: @invoice.filename
2016-05-04 18:17:50 +02:00
end
private
def per_page
params[:per_page] || 20
end
2016-05-04 18:17:50 +02:00
end