From 9d0a11c2b6b767762707d3d4473e15ba3318d8e2 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 31 Dec 2019 12:35:43 -0300 Subject: [PATCH] Bug 24321: Clean /patrons/{patron_id}/account Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/REST/V1/Patrons/Account.pm | 96 ------------------------ t/db_dependent/api/v1/patrons_accounts.t | 6 +- 2 files changed, 3 insertions(+), 99 deletions(-) diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm index 63888cd082..208406aef3 100644 --- a/Koha/REST/V1/Patrons/Account.pm +++ b/Koha/REST/V1/Patrons/Account.pm @@ -157,100 +157,4 @@ sub add_credit { }; } - -=head3 _to_api - -Helper function that maps unblessed Koha::Account::Line objects -into REST API attribute names. - -=cut - -sub _to_api { - my $account_line = shift; - - # Rename attributes - foreach my $column ( keys %{ $Koha::REST::V1::Patrons::Account::to_api_mapping } ) { - my $mapped_column = $Koha::REST::V1::Patrons::Account::to_api_mapping->{$column}; - if ( exists $account_line->{ $column } - && defined $mapped_column ) - { - # key != undef - $account_line->{ $mapped_column } = delete $account_line->{ $column }; - } - elsif ( exists $account_line->{ $column } - && !defined $mapped_column ) - { - # key == undef - delete $account_line->{ $column }; - } - } - - return $account_line; -} - -=head3 _to_model - -Helper function that maps REST API objects into Koha::Account::Line -attribute names. - -=cut - -sub _to_model { - my $account_line = shift; - - foreach my $attribute ( keys %{ $Koha::REST::V1::Patrons::Account::to_model_mapping } ) { - my $mapped_attribute = $Koha::REST::V1::Patrons::Account::to_model_mapping->{$attribute}; - if ( exists $account_line->{ $attribute } - && defined $mapped_attribute ) - { - # key => !undef - $account_line->{ $mapped_attribute } = delete $account_line->{ $attribute }; - } - elsif ( exists $account_line->{ $attribute } - && !defined $mapped_attribute ) - { - # key => undef / to be deleted - delete $account_line->{ $attribute }; - } - } - - return $account_line; -} - -=head2 Global variables - -=head3 $to_api_mapping - -=cut - -our $to_api_mapping = { - accountlines_id => 'account_line_id', - credit_type_code => 'credit_type', - debit_type_code => 'debit_type', - amountoutstanding => 'amount_outstanding', - borrowernumber => 'patron_id', - branchcode => 'library_id', - issue_id => 'checkout_id', - itemnumber => 'item_id', - manager_id => 'user_id', - note => 'internal_note', -}; - -=head3 $to_model_mapping - -=cut - -our $to_model_mapping = { - account_line_id => 'accountlines_id', - credit_type => 'credit_type_code', - debit_type => 'debit_type_code', - amount_outstanding => 'amountoutstanding', - checkout_id => 'issue_id', - internal_note => 'note', - item_id => 'itemnumber', - library_id => 'branchcode', - patron_id => 'borrowernumber', - user_id => 'manager_id' -}; - 1; diff --git a/t/db_dependent/api/v1/patrons_accounts.t b/t/db_dependent/api/v1/patrons_accounts.t index 6921931c1b..773a6b2e66 100644 --- a/t/db_dependent/api/v1/patrons_accounts.t +++ b/t/db_dependent/api/v1/patrons_accounts.t @@ -97,8 +97,8 @@ subtest 'get_balance() tests' => sub { outstanding_debits => { total => 100.01, lines => [ - Koha::REST::V1::Patrons::Account::_to_api( $account_line_1->TO_JSON ), - Koha::REST::V1::Patrons::Account::_to_api( $account_line_2->TO_JSON ) + $account_line_1->to_api, + $account_line_2->to_api ] }, outstanding_credits => { @@ -144,7 +144,7 @@ subtest 'get_balance() tests' => sub { }, outstanding_credits => { total => -10, - lines => [ Koha::REST::V1::Patrons::Account::_to_api( $credit_line->TO_JSON ) ] + lines => [ $credit_line->to_api ] } } ); -- 2.39.5