mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-03-15 12:29:16 +01:00
(wip) accounting endpoint for the OpenAPI
This commit is contained in:
parent
85ec08ae67
commit
514a797b64
27
app/controllers/open_api/v1/accounting_controller.rb
Normal file
27
app/controllers/open_api/v1/accounting_controller.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# 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
|
76
app/doc/open_api/v1/accounting_doc.rb
Normal file
76
app/doc/open_api/v1/accounting_doc.rb
Normal file
@ -0,0 +1,76 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# openAPI documentation for accounting endpoints
|
||||
class OpenAPI::V1::AccountingDoc < OpenAPI::V1::BaseDoc
|
||||
resource_description do
|
||||
short 'Accounting lines'
|
||||
desc 'Accounting lines according to the French General Accounting Plan (PCG)'
|
||||
formats FORMATS
|
||||
api_version API_VERSION
|
||||
end
|
||||
|
||||
include OpenAPI::V1::Concerns::ParamGroups
|
||||
|
||||
doc_for :index do
|
||||
api :GET, "/#{API_VERSION}/accounting", 'Accounting lines'
|
||||
description 'All accounting lines, with optional pagination and dates filtering. Ordered by *date* descendant.'
|
||||
param_group :pagination
|
||||
param :after, DateTime, optional: true, desc: 'Filter accounting lines to lines after the given date.'
|
||||
param :before, DateTime, optional: true, desc: 'Filter accounting lines to lines before the given date.'
|
||||
example <<-LINES
|
||||
# /open_api/v1/accounting?after=2022-01-01T00:00:00+02:00&page=1&per_page=3
|
||||
{
|
||||
"lines": [
|
||||
{
|
||||
"journal_code": "VT01",
|
||||
"date": "2022-01-02T18:14:21+01:00",
|
||||
"account_code": "5802",
|
||||
"account_label": "Wallet customers",
|
||||
"analytical_code": "P3D71",
|
||||
"invoice": {
|
||||
"reference": "22010009/VL",
|
||||
"id": 274,
|
||||
"label": "Dupont Marcel, 22010009/VL, subscr.",
|
||||
},
|
||||
"user_id": 6512,
|
||||
"amount": 200,
|
||||
"currency": "EUR",
|
||||
"invoice_url": "/open_api/v1/invoices/247/download"
|
||||
},
|
||||
{
|
||||
"journal_code": "VT01",
|
||||
"date": "2022-01-02T18:14:21+01:00",
|
||||
"account_code": "5801",
|
||||
"account_label": "Card customers",
|
||||
"analytical_code": "P3D71",
|
||||
"invoice": {
|
||||
"reference": "22010009/VL",
|
||||
"id": 274,
|
||||
"label": "Dupont Marcel, 22010009/VL, subscr.",
|
||||
},
|
||||
"user_id": 6512,
|
||||
"amount": 100,
|
||||
"currency": "EUR",
|
||||
"invoice_url": "/open_api/v1/invoices/247/download"
|
||||
},
|
||||
{
|
||||
"journal_code": "VT01",
|
||||
"date": "2022-01-02T18:14:21+01:00",
|
||||
"account_code": "5802",
|
||||
"account_label": "Wallet customers",
|
||||
"analytical_code": "P3D71",
|
||||
"invoice": {
|
||||
"reference": "22010009/VL",
|
||||
"id": 274,
|
||||
"label": "Dupont Marcel, 22010009/VL, subscr.",
|
||||
},
|
||||
"user_id": 6512,
|
||||
"amount": 200,
|
||||
"currency": "EUR",
|
||||
"invoice_url": "/open_api/v1/invoices/247/download"
|
||||
}
|
||||
]
|
||||
}
|
||||
LINES
|
||||
end
|
||||
end
|
16
test/integration/open_api/accounting_test.rb
Normal file
16
test/integration/open_api/accounting_test.rb
Normal file
@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
module OpenApi; end
|
||||
|
||||
class OpenApi::AccountingTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
||||
end
|
||||
|
||||
test 'list all accounting lines' do
|
||||
get '/open_api/v1/accounting', headers: open_api_headers(@token)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user