Bugzilla – Attachment 94620 Details for
Bug 23843
Make existing endpoints use Koha::Object(s)->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23843: Add mapping to Koha::Account::Line
Bug-23843-Add-mapping-to-KohaAccountLine.patch (text/plain), 3.36 KB, created by
Joonas Kylmälä
on 2019-10-23 14:11:48 UTC
(
hide
)
Description:
Bug 23843: Add mapping to Koha::Account::Line
Filename:
MIME Type:
Creator:
Joonas Kylmälä
Created:
2019-10-23 14:11:48 UTC
Size:
3.36 KB
patch
obsolete
>From 52969221d4fbb0c663ce2dbc1bec7705a1b2b2c8 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 21 Oct 2019 13:24:27 -0300 >Subject: [PATCH] Bug 23843: Add mapping to Koha::Account::Line >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds a to_api_mapping method to the class. This in effect >enables calling ->to_api on the object. The mapping is borrowed from the >API controller. It is not removed from the controller so we are able to >verify (through the tests) that there is no behavior change. > >Once this is pushed we need to implement the counter-wise methods and >clean the controllers. > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/api/v1/patrons_accounts.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat (1) >=> SUCCESS: Tests still pass! >4. Sign off :-D > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> >--- > Koha/Account/Line.pm | 21 +++++++++++++++++++++ > Koha/REST/V1/Patrons/Account.pm | 30 ++++++++++++++---------------- > 2 files changed, 35 insertions(+), 16 deletions(-) > >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index 124aa29153..ae7bbc145d 100644 >--- a/Koha/Account/Line.pm >+++ b/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::Account::Line 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 >diff --git a/Koha/REST/V1/Patrons/Account.pm b/Koha/REST/V1/Patrons/Account.pm >index eb495f924e..d7263d81be 100644 >--- a/Koha/REST/V1/Patrons/Account.pm >+++ b/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 >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23843
:
94470
|
94471
|
94472
|
94473
|
94474
|
94475
|
94476
|
94477
|
94478
|
94496
|
94506
|
94507
|
94508
|
94509
|
94510
|
94511
|
94512
|
94513
|
94514
|
94587
|
94588
|
94589
|
94590
|
94591
|
94592
|
94593
|
94594
|
94595
|
94596
|
94619
| 94620 |
94621
|
94622
|
94623
|
94624
|
94625
|
94626
|
94627
|
94628