Bug 24321: Clean /patrons/{patron_id}/account
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Dec 2019 15:35:43 +0000 (12:35 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 8 Jan 2020 14:42:52 +0000 (14:42 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Koha/REST/V1/Patrons/Account.pm
t/db_dependent/api/v1/patrons_accounts.t

index 63888cd..208406a 100644 (file)
@@ -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;
index 6921931..773a6b2 100644 (file)
@@ -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 ]
             }
         }
     );