From 9536bb546ca8a3b382291cb3a649f050b0f0db04 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 31 Dec 2019 12:26:46 -0300 Subject: [PATCH] Bug 24321: Clean /biblios Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall --- Koha/Biblio.pm | 20 +++++++++++ Koha/Biblioitem.pm | 34 +++++++++++++++++-- Koha/REST/V1/Biblios.pm | 73 +++-------------------------------------- 3 files changed, 56 insertions(+), 71 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 5b63653aec..8c26db04fb 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -724,6 +724,26 @@ sub custom_cover_image_url { return $url; } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Biblio object +on the API. + +=cut + +sub to_api_mapping { + return { + biblionumber => 'biblio_id', + frameworkcode => 'framework_id', + unititle => 'uniform_title', + seriestitle => 'series_title', + copyrightdate => 'copyright_date', + datecreated => 'creation_date' + }; +} + +=head2 Internal methods + =head3 type =cut diff --git a/Koha/Biblioitem.pm b/Koha/Biblioitem.pm index 8d353c8f0b..e524f8375d 100644 --- a/Koha/Biblioitem.pm +++ b/Koha/Biblioitem.pm @@ -29,11 +29,41 @@ Koha::Biblioitem - Koha Biblioitem Object class =head1 API -=head2 Class Methods +=head2 Class methods + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Biblioitem object +on the API. =cut -=head3 type +sub to_api_mapping { + return { + agerestriction => 'age_restriction', + biblioitemnumber => undef, # meaningless + collectionissn => 'collection_issn', + collectiontitle => 'collection_title', + collectionvolume => 'collection_volume', + editionresponsibility => undef, # obsolete, not mapped + editionstatement => 'edition_statement', + illus => 'illustrations', + itemtype => 'item_type', + lccn => 'lc_control_number', + place => 'publication_place', + publicationyear => 'publication_year', + publishercode => 'publisher', + size => 'material_size', + totalissues => 'serial_total_issues', + volumedate => 'volume_date', + volumedesc => 'volume_description', + + }; +} + +=head2 Internal methods + +=head3 _type =cut diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index b3cba7c8d3..498a0c8172 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -28,7 +28,7 @@ use Try::Tiny; =head1 API -=head2 Class methods +=head2 Methods =head3 get @@ -150,38 +150,6 @@ sub delete { =head2 Internal methods - -=head3 _to_api - -Helper function that maps unblessed Koha::Patron objects into REST api -attribute names. - -=cut - -sub _to_api { - my $biblio = shift; - - # Rename attributes - foreach my $column ( keys %{$Koha::REST::V1::Biblios::to_api_mapping} ) { - my $mapped_column = $Koha::REST::V1::Biblios::to_api_mapping->{$column}; - if ( exists $biblio->{$column} - && defined $mapped_column ) - { - # key != undef - $biblio->{$mapped_column} = delete $biblio->{$column}; - } - elsif ( exists $biblio->{$column} - && !defined $mapped_column ) - { - # key == undef - delete $biblio->{$column}; - } - } - - return $biblio; -} - - =head3 build_json_biblio Internal method that returns all the attributes from the biblio and biblioitems tables @@ -193,47 +161,14 @@ sub build_json_biblio { my $biblio = $args->{biblio}; - my $response = $biblio->TO_JSON; - my $biblioitem = $biblio->biblioitem->TO_JSON; + my $response = $biblio->to_api; + my $biblioitem = $biblio->biblioitem->to_api; foreach my $key ( keys %{ $biblioitem } ) { $response->{$key} = $biblioitem->{$key}; } - return _to_api($response); + return $response; } - -=head2 Global variables - -=head3 $to_api_mapping - -=cut - -our $to_api_mapping = { - agerestriction => 'age_restriction', - biblioitemnumber => undef, # meaningless - biblionumber => 'biblio_id', - collectionissn => 'collection_issn', - collectiontitle => 'collection_title', - collectionvolume => 'collection_volume', - copyrightdate => 'copyright_date', - datecreated => 'creation_date', - editionresponsibility => undef, # obsolete, not mapped - editionstatement => 'edition_statement', - frameworkcode => 'framework_id', - illus => 'illustrations', - itemtype => 'item_type', - lccn => 'lc_control_number', - place => 'publication_place', - publicationyear => 'publication_year', - publishercode => 'publisher', - seriestitle => 'series_title', - size => 'material_size', - totalissues => 'serial_total_issues', - unititle => 'uniform_title', - volumedate => 'volume_date', - volumedesc => 'volume_description', -}; - 1; -- 2.21.0 (Apple Git-122.2)