Bugzilla – Attachment 94476 Details for
Bug 23843
Make existing endpoints use Koha::Object(s)->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23843: Add mapping to Koha::Item
Bug-23843-Add-mapping-to-KohaItem.patch (text/plain), 4.36 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-10-21 16:57:46 UTC
(
hide
)
Description:
Bug 23843: Add mapping to Koha::Item
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-10-21 16:57:46 UTC
Size:
4.36 KB
patch
obsolete
>From a5d7f23c8af4f4c33ba24ab2ea3fae79e893eb4e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 21 Oct 2019 13:27:25 -0300 >Subject: [PATCH] Bug 23843: Add mapping to Koha::Item > >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 >--- > 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.23.0
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 23843
:
94470
|
94471
|
94472
|
94473
|
94474
|
94475
|
94476
|
94477
|
94478
|
94496
|
94506
|
94507
|
94508
|
94509
|
94510
|
94511
|
94512
|
94513
|
94514
|
94587
|
94588
|
94589
|
94590
|
94591
|
94592
|
94593
|
94594
|
94595
|
94596
|
94619
|
94620
|
94621
|
94622
|
94623
|
94624
|
94625
|
94626
|
94627
|
94628