Bugzilla – Attachment 94477 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::Acquisition::Bookseller
Bug-23843-Add-mapping-to-KohaAcquisitionBookseller.patch (text/plain), 4.01 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-10-21 16:57:49 UTC
(
hide
)
Description:
Bug 23843: Add mapping to Koha::Acquisition::Bookseller
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-10-21 16:57:49 UTC
Size:
4.01 KB
patch
obsolete
>From 5b51471e86ca35e41ed37fae79c66f5b9d1c95be Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 21 Oct 2019 13:29:47 -0300 >Subject: [PATCH] Bug 23843: Add mapping to Koha::Acquisition::Bookseller > >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/acquisitions_vendors.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat (1) >=> SUCCESS: Tests still pass! >4. Sign off :-D >--- > Koha/Acquisition/Bookseller.pm | 24 ++++++++++++++++++++++- > Koha/REST/V1/Acquisitions/Vendors.pm | 29 ++++++++++++++++------------ > 2 files changed, 40 insertions(+), 13 deletions(-) > >diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm >index f2f08db109..708ae51461 100644 >--- a/Koha/Acquisition/Bookseller.pm >+++ b/Koha/Acquisition/Bookseller.pm >@@ -28,7 +28,7 @@ Koha::Acquisition::Bookseller Object class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =head3 baskets > >@@ -73,6 +73,28 @@ sub subscriptions { > return Koha::Subscriptions->search( { aqbooksellerid => $self->id } ); > } > >+=head3 to_api_mapping >+ >+This method returns the mapping for representing a Koha::Acquisition::Bookseller object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ booksellerfax => undef, >+ bookselleremail => undef, >+ booksellerurl => undef, >+ currency => undef, >+ othersupplier => undef, >+ listprice => 'list_currency', >+ invoiceprice => 'invoice_currency', >+ gstreg => 'gst', >+ listincgst => 'list_includes_gst', >+ invoiceincgst => 'invoice_includes_gst' >+ }; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm >index 5f86ac82d4..f5686b0ded 100644 >--- a/Koha/REST/V1/Acquisitions/Vendors.pm >+++ b/Koha/REST/V1/Acquisitions/Vendors.pm >@@ -48,13 +48,12 @@ sub list_vendors { > if $args->{$filter_param}; > } > >- my @vendors; >- > return try { >- @vendors = Koha::Acquisition::Booksellers->search($filter); >- @vendors = map { _to_api($_->TO_JSON) } @vendors; >- return $c->render( status => 200, >- openapi => \@vendors ); >+ my $vendors = Koha::Acquisition::Booksellers->search($filter); >+ return $c->render( >+ status => 200, >+ openapi => $vendors->to_api >+ ); > } > catch { > if ( $_->isa('DBIx::Class::Exception') ) { >@@ -83,8 +82,10 @@ sub get_vendor { > openapi => { error => "Vendor not found" } ); > } > >- return $c->render( status => 200, >- openapi => _to_api($vendor->TO_JSON) ); >+ return $c->render( >+ status => 200, >+ openapi => $vendor->to_api >+ ); > } > > =head3 add_vendor >@@ -100,8 +101,10 @@ sub add_vendor { > > return try { > $vendor->store; >- return $c->render( status => 200, >- openapi => _to_api($vendor->TO_JSON) ); >+ return $c->render( >+ status => 200, >+ openapi => $vendor->to_api >+ ); > } > catch { > if ( $_->isa('DBIx::Class::Exception') ) { >@@ -130,8 +133,10 @@ sub update_vendor { > $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') ); > $vendor->set( _to_model( $c->validation->param('body') ) ); > $vendor->store(); >- return $c->render( status => 200, >- openapi => _to_api($vendor->TO_JSON) ); >+ return $c->render( >+ status => 200, >+ openapi => $vendor->to_api >+ ); > } > catch { > if ( not defined $vendor ) { >-- >2.23.0
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