From 15f3bd12c71a5e3ede368d7d8e7ea2dafa0c6c2d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 21 Oct 2019 13:27:25 -0300 Subject: [PATCH] Bug 23843: Add mapping to Koha::Item MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/items.t => SUCCESS: Tests pass 2. Apply this patch 3. Repeat (1) => SUCCESS: Tests still pass! 4. Sign off :-D Signed-off-by: Martin Renvoize Signed-off-by: Joonas Kylmälä --- Koha/Item.pm | 57 +++++++++++++++++++++++++++++++++++++++++++ Koha/REST/V1/Items.pm | 6 +---- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 2b2eb5fffc..5c95b35840 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -429,6 +429,63 @@ sub as_marc_field { return $field; } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Item object +on the API. + +=cut + +sub to_api_mapping { + return { + itemnumber => 'item_id', + biblionumber => 'biblio_id', + biblioitemnumber => undef, + barcode => 'external_id', + dateaccessioned => 'acquisition_date', + booksellerid => 'acquisition_source', + homebranch => 'home_library_id', + price => 'purchase_price', + replacementprice => 'replacement_price', + replacementpricedate => 'replacement_price_date', + datelastborrowed => 'last_checkout_date', + datelastseen => 'last_seen_date', + stack => undef, + notforloan => 'not_for_loan_status', + damaged => 'damaged_status', + damaged_on => 'damaged_date', + itemlost => 'lost_status', + itemlost_on => 'lost_date', + withdrawn => 'withdrawn', + withdrawn_on => 'withdrawn_date', + itemcallnumber => 'callnumber', + coded_location_qualifier => 'coded_location_qualifier', + issues => 'checkouts_count', + renewals => 'renewals_count', + reserves => 'holds_count', + restricted => 'restricted_status', + itemnotes => 'public_notes', + itemnotes_nonpublic => 'internal_notes', + holdingbranch => 'holding_library_id', + paidfor => undef, + timestamp => 'timestamp', + location => 'location', + permanent_location => 'permanent_location', + onloan => 'checked_out_date', + cn_source => 'call_number_source', + cn_sort => 'call_number_sort', + ccode => 'collection_code', + materials => 'materials_notes', + uri => 'uri', + itype => 'item_type', + more_subfields_xml => 'extended_subfields', + enumchron => 'serial_issue_number', + copynumber => 'copy_number', + stocknumber => 'inventory_number', + new_status => 'new_status' + }; +} + =head2 Internal methods =head3 _type diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm index d93af2e6bc..d8c802cd96 100644 --- a/Koha/REST/V1/Items.pm +++ b/Koha/REST/V1/Items.pm @@ -18,10 +18,6 @@ package Koha::REST::V1::Items; use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; -use Mojo::JSON; - -use C4::Auth qw( haspermission ); -use C4::Items qw( GetHiddenItemnumbers ); use Koha::Items; @@ -33,7 +29,7 @@ sub get { my $item; try { $item = Koha::Items->find($c->validation->param('item_id')); - return $c->render( status => 200, openapi => _to_api( $item->TO_JSON ) ); + return $c->render( status => 200, openapi => $item->to_api ); } catch { unless ( defined $item ) { -- 2.17.1