API v1 financial_transaction_types endpoint

This commit is contained in:
Patrick Gansterer 2021-02-08 01:08:52 +01:00
parent 48391f818f
commit be269101f8
5 changed files with 137 additions and 0 deletions

View file

@ -0,0 +1,26 @@
class Api::V1::FinancialTransactionTypesController < Api::V1::BaseController
include Concerns::CollectionScope
def index
render json: search_scope
end
def show
render json: scope.find(params.require(:id))
end
private
def max_per_page
nil
end
def default_per_page
nil
end
def scope
FinancialTransactionType.includes(:bank_account, :financial_transaction_class)
end
end

View file

@ -0,0 +1,17 @@
class FinancialTransactionTypeSerializer < ActiveModel::Serializer
attributes :id, :name, :name_short
attributes :bank_account_id, :bank_account_name, :bank_account_iban
attributes :financial_transaction_class_id, :financial_transaction_class_name
def financial_transaction_class_name
object.financial_transaction_class.name
end
def bank_account_name
object.bank_account.try(:name)
end
def bank_account_iban
object.bank_account.try(:iban)
end
end

View file

@ -266,6 +266,7 @@ Rails.application.routes.draw do
end
resources :financial_transaction_classes, only: [:index, :show]
resources :financial_transaction_types, only: [:index, :show]
resources :financial_transactions, only: [:index, :show]
end
end

View file

@ -233,6 +233,59 @@ paths:
security:
- foodsoft_auth: ['all']
/financial_transaction_types:
get:
summary: financial transaction types
tags:
- 2. Category
parameters:
- $ref: '#/parameters/page'
- $ref: '#/parameters/per_page'
responses:
200:
description: success
schema:
type: object
properties:
financial_transaction_types:
type: array
items:
$ref: '#/definitions/FinancialTransactionType'
meta:
$ref: '#/definitions/Meta'
401:
description: not logged-in
schema:
$ref: '#/definitions/Error401'
security:
- foodsoft_auth: ['all']
/financial_transaction_types/{id}:
parameters:
- $ref: '#/parameters/idInUrl'
get:
summary: find financial transaction type by id
tags:
- 2. Category
responses:
200:
description: success
schema:
type: object
properties:
financial_transaction_type:
$ref: '#/definitions/FinancialTransactionType'
401:
description: not logged-in
schema:
$ref: '#/definitions/Error401'
404:
description: not found
schema:
$ref: '#/definitions/Error404'
security:
- foodsoft_auth: ['all']
/config:
get:
summary: configuration variables
@ -349,6 +402,34 @@ definitions:
description: full name
required: ['id', 'name']
FinancialTransactionType:
type: object
properties:
id:
type: integer
name:
type: string
description: full name
name_short:
type: ['string', 'null']
description: short name (used for bank transfers)
bank_account_id:
type: ['integer', 'null']
description: id of the bank account used for this transaction type
bank_account_name:
type: ['string', 'null']
description: name of the bank account used for this transaction type
bank_account_iban:
type: ['string', 'null']
description: IBAN of the bank account used for this transaction type
financial_transaction_class_id:
type: integer
description: id of the class of the transaction
financial_transaction_class_name:
type: string
description: name of the class of the transaction
required: ['id', 'name', 'financial_transaction_class_id', 'financial_transaction_class_name']
Navigation:
type: array
items:

View file

@ -101,6 +101,18 @@ describe 'API v1', type: :apivore, order: :defined do
it_handles_invalid_token(:get, '/financial_transaction_classes')
it_handles_invalid_token(:get, '/financial_transaction_classes/{id}', ->{ api_auth({'id' => cla_1.id }) })
end
context 'financial_transaction_types' do
let!(:tpy_1) { create :financial_transaction_type }
let!(:tpy_2) { create :financial_transaction_type }
it { is_expected.to validate(:get, '/financial_transaction_types', 200, api_auth) }
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 200, api_auth({'id' => tpy_2.id})) }
it { is_expected.to validate(:get, '/financial_transaction_types/{id}', 404, api_auth({'id' => tpy_2.id + 1})) }
it_handles_invalid_token(:get, '/financial_transaction_types')
it_handles_invalid_token(:get, '/financial_transaction_types/{id}', ->{ api_auth({'id' => tpy_1.id }) })
end
end
# needs to be last context so it is always run at the end