Bugzilla – Attachment 96950 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 /holds
Bug-24321-Clean-holds.patch (text/plain), 5.88 KB, created by
Kyle M Hall (khall)
on 2020-01-07 18:50:40 UTC
(
hide
)
Description:
Bug 24321: Clean /holds
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-01-07 18:50:40 UTC
Size:
5.88 KB
patch
obsolete
>From fae280031cf6c5b86069ff8f21a3e68763ec3cf6 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 12:53:26 -0300 >Subject: [PATCH] Bug 24321: Clean /holds > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/V1/Holds.pm | 151 ++---------------------------------------- > 1 file changed, 4 insertions(+), 147 deletions(-) > >diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm >index 41e93fc308..7d181b927d 100644 >--- a/Koha/REST/V1/Holds.pm >+++ b/Koha/REST/V1/Holds.pm >@@ -31,7 +31,7 @@ use Try::Tiny; > > =head1 API > >-=head2 Class methods >+=head2 Methods > > =head3 list > >@@ -44,7 +44,7 @@ sub list { > > return try { > my $holds_set = Koha::Holds->new; >- my $holds = $c->objects->search( $holds_set, \&_to_model, \&_to_api ); >+ my $holds = $c->objects->search( $holds_set ); > return $c->render( status => 200, openapi => $holds ); > } > catch { >@@ -194,10 +194,10 @@ sub add { > if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { > my $broken_fk = $_->broken_fk; > >- if ( grep { $_ eq $broken_fk } keys %{$Koha::REST::V1::Holds::to_api_mapping} ) { >+ if ( grep { $_ eq $broken_fk } keys %{Koha::Holds->new->to_api_mapping} ) { > $c->render( > status => 404, >- openapi => $Koha::REST::V1::Holds::to_api_mapping->{$broken_fk} . ' not found.' >+ openapi => Koha::Holds->new->to_api_mapping->{$broken_fk} . ' not found.' > ); > } > else { >@@ -403,147 +403,4 @@ sub update_priority { > }; > } > >-=head2 Internal methods >- >-=head3 _to_api >- >-Helper function that maps unblessed Koha::Hold objects into REST api >-attribute names. >- >-=cut >- >-sub _to_api { >- my $hold = shift; >- >- # Rename attributes >- foreach my $column ( keys %{ $Koha::REST::V1::Holds::to_api_mapping } ) { >- my $mapped_column = $Koha::REST::V1::Holds::to_api_mapping->{$column}; >- if ( exists $hold->{ $column } >- && defined $mapped_column ) >- { >- # key != undef >- $hold->{ $mapped_column } = delete $hold->{ $column }; >- } >- elsif ( exists $hold->{ $column } >- && !defined $mapped_column ) >- { >- # key == undef >- delete $hold->{ $column }; >- } >- } >- >- return $hold; >-} >- >-=head3 _to_model >- >-Helper function that maps REST api objects into Koha::Hold >-attribute names. >- >-=cut >- >-sub _to_model { >- my $hold = shift; >- >- foreach my $attribute ( keys %{ $Koha::REST::V1::Holds::to_model_mapping } ) { >- my $mapped_attribute = $Koha::REST::V1::Holds::to_model_mapping->{$attribute}; >- if ( exists $hold->{ $attribute } >- && defined $mapped_attribute ) >- { >- # key => !undef >- $hold->{ $mapped_attribute } = delete $hold->{ $attribute }; >- } >- elsif ( exists $hold->{ $attribute } >- && !defined $mapped_attribute ) >- { >- # key => undef / to be deleted >- delete $hold->{ $attribute }; >- } >- } >- >- if ( exists $hold->{lowestPriority} ) { >- $hold->{lowestPriority} = ($hold->{lowestPriority}) ? 1 : 0; >- } >- >- if ( exists $hold->{suspend} ) { >- $hold->{suspend} = ($hold->{suspend}) ? 1 : 0; >- } >- >- if ( exists $hold->{reservedate} ) { >- $hold->{reservedate} = output_pref({ str => $hold->{reservedate}, dateformat => 'sql' }); >- } >- >- if ( exists $hold->{cancellationdate} ) { >- $hold->{cancellationdate} = output_pref({ str => $hold->{cancellationdate}, dateformat => 'sql' }); >- } >- >- if ( exists $hold->{timestamp} ) { >- $hold->{timestamp} = output_pref({ str => $hold->{timestamp}, dateformat => 'sql' }); >- } >- >- if ( exists $hold->{waitingdate} ) { >- $hold->{waitingdate} = output_pref({ str => $hold->{waitingdate}, dateformat => 'sql' }); >- } >- >- if ( exists $hold->{expirationdate} ) { >- $hold->{expirationdate} = output_pref({ str => $hold->{expirationdate}, dateformat => 'sql' }); >- } >- >- if ( exists $hold->{suspend_until} ) { >- $hold->{suspend_until} = output_pref({ str => $hold->{suspend_until}, dateformat => 'sql' }); >- } >- >- return $hold; >-} >- >-=head2 Global variables >- >-=head3 $to_api_mapping >- >-=cut >- >-our $to_api_mapping = { >- reserve_id => 'hold_id', >- borrowernumber => 'patron_id', >- reservedate => 'hold_date', >- biblionumber => 'biblio_id', >- branchcode => 'pickup_library_id', >- notificationdate => undef, >- reminderdate => undef, >- cancellationdate => 'cancelation_date', >- reservenotes => 'notes', >- found => 'status', >- itemnumber => 'item_id', >- waitingdate => 'waiting_date', >- expirationdate => 'expiration_date', >- lowestPriority => 'lowest_priority', >- suspend => 'suspended', >- suspend_until => 'suspended_until', >- itemtype => 'item_type', >- item_level_hold => 'item_level', >-}; >- >-=head3 $to_model_mapping >- >-=cut >- >-our $to_model_mapping = { >- hold_id => 'reserve_id', >- patron_id => 'borrowernumber', >- hold_date => 'reservedate', >- biblio_id => 'biblionumber', >- pickup_library_id => 'branchcode', >- cancelation_date => 'cancellationdate', >- notes => 'reservenotes', >- status => 'found', >- item_id => 'itemnumber', >- waiting_date => 'waitingdate', >- expiration_date => 'expirationdate', >- lowest_priority => 'lowestPriority', >- suspended => 'suspend', >- suspended_until => 'suspend_until', >- item_type => 'itemtype', >- item_level => 'item_level_hold', >-}; >- > 1; >-- >2.21.0 (Apple Git-122.2)
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