Bug 24321: Clean /biblios
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Dec 2019 15:26:46 +0000 (12:26 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 8 Jan 2020 14:42:43 +0000 (14:42 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Koha/Biblio.pm
Koha/Biblioitem.pm
Koha/REST/V1/Biblios.pm

index 5b63653..8c26db0 100644 (file)
@@ -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
index 8d353c8..e524f83 100644 (file)
@@ -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
 
index b3cba7c..498a0c8 100644 (file)
@@ -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;