@@ -, +, @@ $ kshell k$ prove t/db_dependent/api/v1/patrons_accounts.t --- Koha/Account/Line.pm | 21 +++++++++++++++++++++ Koha/REST/V1/Patrons/Account.pm | 30 ++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) --- a/Koha/Account/Line.pm +++ a/Koha/Account/Line.pm @@ -398,6 +398,27 @@ sub is_debit { return !$self->is_credit; } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Item object +on the API. + +=cut + +sub to_api_mapping { + return { + accountlines_id => 'account_line_id', + accounttype => 'account_type', + amountoutstanding => 'amount_outstanding', + borrowernumber => 'patron_id', + branchcode => 'library_id', + issue_id => 'checkout_id', + itemnumber => 'item_id', + manager_id => 'user_id', + note => 'internal_note', + }; +} + =head2 Internal methods =cut --- a/Koha/REST/V1/Patrons/Account.pm +++ a/Koha/REST/V1/Patrons/Account.pm @@ -49,27 +49,25 @@ sub get { } my $account = $patron->account; - my $balance; - - $balance->{balance} = $account->balance; # get outstanding debits and credits my $debits = $account->outstanding_debits; my $credits = $account->outstanding_credits; - my @debit_lines = map { _to_api( $_->TO_JSON ) } @{ $debits->as_list }; - $balance->{outstanding_debits} = { - total => $debits->total_outstanding, - lines => \@debit_lines - }; - - my @credit_lines = map { _to_api( $_->TO_JSON ) } @{ $credits->as_list }; - $balance->{outstanding_credits} = { - total => $credits->total_outstanding, - lines => \@credit_lines - }; - - return $c->render( status => 200, openapi => $balance ); + return $c->render( + status => 200, + openapi => { + balance => $account->balance, + outstanding_debits => { + total => $debits->total_outstanding, + lines => $debits->to_api + }, + outstanding_credits => { + total => $credits->total_outstanding, + lines => $credits->to_api + } + } + ); } =head3 add_credit --