@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Biblio.t \ t/db_dependent/api/v1/biblios.t --- Koha/Biblio.pm | 23 +++++++++++++++++++++++ Koha/Biblioitem.pm | 1 + Koha/REST/V1/Biblios.pm | 25 +------------------------ 3 files changed, 25 insertions(+), 24 deletions(-) --- a/Koha/Biblio.pm +++ a/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 --- a/Koha/Biblioitem.pm +++ a/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', --- a/Koha/REST/V1/Biblios.pm +++ a/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; --