Bugzilla – Attachment 96720 Details for
Bug 24321
Make objects.search use mappings from Koha::Object(s)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24321: Clean /items
Bug-24321-Clean-items.patch (text/plain), 6.64 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-12-31 15:32:06 UTC
(
hide
)
Description:
Bug 24321: Clean /items
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-12-31 15:32:06 UTC
Size:
6.64 KB
patch
obsolete
>From 16488d2fb368694ee722462b9edbed3018a661b4 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 12:31:24 -0300 >Subject: [PATCH] Bug 24321: Clean /items > >--- > Koha/REST/V1/Items.pm | 166 +--------------------------------- > t/db_dependent/api/v1/items.t | 4 +- > 2 files changed, 3 insertions(+), 167 deletions(-) > >diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm >index f69944c5b9..00234f2918 100644 >--- a/Koha/REST/V1/Items.pm >+++ b/Koha/REST/V1/Items.pm >@@ -44,7 +44,7 @@ sub list { > > return try { > my $items_set = Koha::Items->new; >- my $items = $c->objects->search( $items_set, \&_to_model, \&_to_api ); >+ my $items = $c->objects->search( $items_set ); > return $c->render( > status => 200, > openapi => $items >@@ -98,168 +98,4 @@ sub get { > }; > } > >-=head2 Internal methods >- >-=head3 _to_api >- >-Helper function that maps unblessed Koha::Hold objects into REST api >-attribute names. >- >-=cut >- >-sub _to_api { >- my $item = shift; >- >- # Rename attributes >- foreach my $column ( keys %{ $Koha::REST::V1::Items::to_api_mapping } ) { >- my $mapped_column = $Koha::REST::V1::Items::to_api_mapping->{$column}; >- if ( exists $item->{ $column } >- && defined $mapped_column ) >- { >- # key != undef >- $item->{ $mapped_column } = delete $item->{ $column }; >- } >- elsif ( exists $item->{ $column } >- && !defined $mapped_column ) >- { >- # key == undef >- delete $item->{ $column }; >- } >- } >- >- return $item; >-} >- >-=head3 _to_model >- >-Helper function that maps REST api objects into Koha::Hold >-attribute names. >- >-=cut >- >-sub _to_model { >- my $item = shift; >- >- foreach my $attribute ( keys %{ $Koha::REST::V1::Items::to_model_mapping } ) { >- my $mapped_attribute = $Koha::REST::V1::Items::to_model_mapping->{$attribute}; >- if ( exists $item->{ $attribute } >- && defined $mapped_attribute ) >- { >- # key => !undef >- $item->{ $mapped_attribute } = delete $item->{ $attribute }; >- } >- elsif ( exists $item->{ $attribute } >- && !defined $mapped_attribute ) >- { >- # key => undef / to be deleted >- delete $item->{ $attribute }; >- } >- } >- >- return $item; >-} >- >-=head2 Global variables >- >-=head3 $to_api_mapping >- >-=cut >- >-our $to_api_mapping = { >- 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' >-}; >- >-=head3 $to_model_mapping >- >-=cut >- >-our $to_model_mapping = { >- item_id => 'itemnumber', >- biblio_id => 'biblionumber', >- external_id => 'barcode', >- acquisition_date => 'dateaccessioned', >- acquisition_source => 'booksellerid', >- home_library_id => 'homebranch', >- purchase_price => 'price', >- replacement_price => 'replacementprice', >- replacement_price_date => 'replacementpricedate', >- last_checkout_date => 'datelastborrowed', >- last_seen_date => 'datelastseen', >- not_for_loan_status => 'notforloan', >- damaged_status => 'damaged', >- damaged_date => 'damaged_on', >- lost_status => 'itemlost', >- lost_date => 'itemlost_on', >- withdrawn => 'withdrawn', >- withdrawn_date => 'withdrawn_on', >- callnumber => 'itemcallnumber', >- coded_location_qualifier => 'coded_location_qualifier', >- checkouts_count => 'issues', >- renewals_count => 'renewals', >- holds_count => 'reserves', >- restricted_status => 'restricted', >- public_notes => 'itemnotes', >- internal_notes => 'itemnotes_nonpublic', >- holding_library_id => 'holdingbranch', >- timestamp => 'timestamp', >- location => 'location', >- permanent_location => 'permanent_location', >- checked_out_date => 'onloan', >- call_number_source => 'cn_source', >- call_number_sort => 'cn_sort', >- collection_code => 'ccode', >- materials_notes => 'materials', >- uri => 'uri', >- item_type => 'itype', >- extended_subfields => 'more_subfields_xml', >- serial_issue_number => 'enumchron', >- copy_number => 'copynumber', >- inventory_number => 'stocknumber', >- new_status => 'new_status' >-}; >- > 1; >diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t >index f60f389a9e..7124c593d9 100644 >--- a/t/db_dependent/api/v1/items.t >+++ b/t/db_dependent/api/v1/items.t >@@ -82,7 +82,7 @@ subtest 'list() tests' => sub { > > $t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) > ->status_is(200) >- ->json_is( '' => [ Koha::REST::V1::Items::_to_api( $item->TO_JSON ) ], 'SWAGGER3.3.2'); >+ ->json_is( '' => [ $item->to_api ], 'SWAGGER3.3.2'); > > my $barcode = $item->barcode; > $item->delete; >@@ -126,7 +126,7 @@ subtest 'get() tests' => sub { > > $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->itemnumber ) > ->status_is( 200, 'SWAGGER3.2.2' ) >- ->json_is( '' => Koha::REST::V1::Items::_to_api( $item->TO_JSON ), 'SWAGGER3.3.2' ); >+ ->json_is( '' => $item->to_api, 'SWAGGER3.3.2' ); > > my $non_existent_code = $item->itemnumber; > $item->delete; >-- >2.24.1
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 24321
:
96703
|
96704
|
96705
|
96706
|
96707
|
96708
|
96709
|
96710
|
96711
|
96712
|
96713
|
96714
|
96715
|
96716
|
96717
|
96718
|
96719
|
96720
|
96721
|
96722
|
96744
|
96840
|
96841
|
96842
|
96843
|
96844
|
96845
|
96846
|
96847
|
96848
|
96849
|
96850
|
96851
|
96852
|
96874
|
96875
|
96876
|
96877
|
96878
|
96879
|
96880
|
96881
|
96882
|
96883
|
96884
|
96885
|
96886
|
96887
|
96939
|
96940
|
96941
|
96942
|
96943
|
96944
|
96945
|
96946
|
96947
|
96948
|
96949
|
96950
|
96951
|
96952