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 Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
255b9b98d0
commit
17a34e3d09
57
Koha/Item.pm
57
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
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue