Bugzilla – Attachment 96959 Details for
Bug 24366
Merging biblioitems should happen in Koha::Biblio->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24366: Merge biblioitem in Koha::Biblio->to_api
Bug-24366-Merge-biblioitem-in-KohaBiblio-toapi.patch (text/plain), 3.40 KB, created by
Kyle M Hall (khall)
on 2020-01-07 19:48:50 UTC
(
hide
)
Description:
Bug 24366: Merge biblioitem in Koha::Biblio->to_api
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-01-07 19:48:50 UTC
Size:
3.40 KB
patch
obsolete
>From acd4d4d28659d149922ed536f452f838b839acd6 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 7 Jan 2020 14:41:50 -0300 >Subject: [PATCH] Bug 24366: Merge biblioitem in Koha::Biblio->to_api > >This patch moves the bilbioitem object merge into the >Koha::Biblio->to_api method, as opposed to doing it in the controller. >This is an inevitable change as other endpoints might require to embed >biblio objects, and they need to carry the biblioitem information. > >Also, if we merge the tables, the transition will be straightforward >(remove the tests this patch introduces, and merge the mappings from >Koha::Biblioitem into Koha::Biblio). > >To test: >1. Apply this patches >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Biblio.t \ > t/db_dependent/api/v1/biblios.t >=> SUCCESS: Tests pass! i.e. the new to_api method is tested, and the >API tests don't expect any behavior change. >3. Sign off :-D > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Biblio.pm | 23 +++++++++++++++++++++++ > Koha/Biblioitem.pm | 1 + > Koha/REST/V1/Biblios.pm | 25 +------------------------ > 3 files changed, 25 insertions(+), 24 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 8c26db04fb..5efc462e03 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -724,6 +724,29 @@ sub custom_cover_image_url { > return $url; > } > >+=head3 to_api >+ >+ my $json = $biblio->to_api; >+ >+Overloaded method that returns a JSON representation of the Koha::Biblio object, >+suitable for API output. The related Koha::Biblioitem object is merged as expected >+on the API. >+ >+=cut >+ >+sub to_api { >+ my ($self, $args) = @_; >+ >+ my $response = $self->SUPER::to_api( $args ); >+ my $biblioitem = $self->biblioitem->to_api( $args ); >+ >+ foreach my $key ( keys %{ $biblioitem } ) { >+ $response->{$key} = $biblioitem->{$key}; >+ } >+ >+ return $response; >+} >+ > =head3 to_api_mapping > > This method returns the mapping for representing a Koha::Biblio object >diff --git a/Koha/Biblioitem.pm b/Koha/Biblioitem.pm >index e524f8375d..c4be1d1beb 100644 >--- a/Koha/Biblioitem.pm >+++ b/Koha/Biblioitem.pm >@@ -41,6 +41,7 @@ on the API. > sub to_api_mapping { > return { > agerestriction => 'age_restriction', >+ biblionumber => 'biblio_id', > biblioitemnumber => undef, # meaningless > collectionissn => 'collection_issn', > collectiontitle => 'collection_title', >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 498a0c8172..9076172413 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -59,7 +59,7 @@ sub get { > if ( $c->req->headers->accept =~ m/application\/json/ ) { > return $c->render( > status => 200, >- json => $c->build_json_biblio( { biblio => $biblio } ) >+ json => $biblio->to_api > ); > } > else { >@@ -148,27 +148,4 @@ sub delete { > }; > } > >-=head2 Internal methods >- >-=head3 build_json_biblio >- >-Internal method that returns all the attributes from the biblio and biblioitems tables >- >-=cut >- >-sub build_json_biblio { >- my ( $c, $args ) = @_; >- >- my $biblio = $args->{biblio}; >- >- my $response = $biblio->to_api; >- my $biblioitem = $biblio->biblioitem->to_api; >- >- foreach my $key ( keys %{ $biblioitem } ) { >- $response->{$key} = $biblioitem->{$key}; >- } >- >- return $response; >-} >- > 1; >-- >2.21.0 (Apple Git-122.2)
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 24366
:
96914
|
96915
|
96958
|
96959
|
97312
|
97313
|
97314
|
97332