API v1 financial_transaction_classes endpoint
This commit is contained in:
parent
aad4fbd5b6
commit
48391f818f
5 changed files with 105 additions and 0 deletions
|
@ -0,0 +1,26 @@
|
|||
class Api::V1::FinancialTransactionClassesController < 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
|
||||
FinancialTransactionClass.all
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class FinancialTransactionClassSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name
|
||||
end
|
|
@ -265,6 +265,7 @@ Rails.application.routes.draw do
|
|||
resources :financial_transactions, only: [:index, :show]
|
||||
end
|
||||
|
||||
resources :financial_transaction_classes, only: [:index, :show]
|
||||
resources :financial_transactions, only: [:index, :show]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -180,6 +180,59 @@ paths:
|
|||
security:
|
||||
- foodsoft_auth: ['finance:read', 'finance:write']
|
||||
|
||||
/financial_transaction_classes:
|
||||
get:
|
||||
summary: financial transaction classes
|
||||
tags:
|
||||
- 2. Category
|
||||
parameters:
|
||||
- $ref: '#/parameters/page'
|
||||
- $ref: '#/parameters/per_page'
|
||||
responses:
|
||||
200:
|
||||
description: success
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
financial_transaction_classes:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/FinancialTransactionClass'
|
||||
meta:
|
||||
$ref: '#/definitions/Meta'
|
||||
401:
|
||||
description: not logged-in
|
||||
schema:
|
||||
$ref: '#/definitions/Error401'
|
||||
|
||||
security:
|
||||
- foodsoft_auth: ['all']
|
||||
/financial_transaction_classes/{id}:
|
||||
parameters:
|
||||
- $ref: '#/parameters/idInUrl'
|
||||
get:
|
||||
summary: find financial transaction class by id
|
||||
tags:
|
||||
- 2. Category
|
||||
responses:
|
||||
200:
|
||||
description: success
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
financial_transaction_class:
|
||||
$ref: '#/definitions/FinancialTransactionClass'
|
||||
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
|
||||
|
@ -286,6 +339,16 @@ definitions:
|
|||
description: when the transaction was entered
|
||||
required: ['id', 'user_id', 'user_name', 'amount', 'note', 'created_at']
|
||||
|
||||
FinancialTransactionClass:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
description: full name
|
||||
required: ['id', 'name']
|
||||
|
||||
Navigation:
|
||||
type: array
|
||||
items:
|
||||
|
|
|
@ -89,6 +89,18 @@ describe 'API v1', type: :apivore, order: :defined do
|
|||
it_handles_invalid_token_and_scope(:get, '/financial_transactions')
|
||||
it_handles_invalid_token_and_scope(:get, '/financial_transactions/{id}', ->{ api_auth({'id' => ft_2.id}) })
|
||||
end
|
||||
|
||||
context 'financial_transaction_classes' do
|
||||
let!(:cla_1) { create :financial_transaction_class }
|
||||
let!(:cla_2) { create :financial_transaction_class }
|
||||
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes', 200, api_auth) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 200, api_auth({'id' => cla_2.id})) }
|
||||
it { is_expected.to validate(:get, '/financial_transaction_classes/{id}', 404, api_auth({'id' => cla_2.id + 1})) }
|
||||
|
||||
it_handles_invalid_token(:get, '/financial_transaction_classes')
|
||||
it_handles_invalid_token(:get, '/financial_transaction_classes/{id}', ->{ api_auth({'id' => cla_1.id }) })
|
||||
end
|
||||
end
|
||||
|
||||
# needs to be last context so it is always run at the end
|
||||
|
|
Loading…
Reference in a new issue