Bugzilla – Attachment 96718 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 /checkouts
Bug-24321-Clean-checkouts.patch (text/plain), 5.96 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-12-31 14:57:42 UTC
(
hide
)
Description:
Bug 24321: Clean /checkouts
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-12-31 14:57:42 UTC
Size:
5.96 KB
patch
obsolete
>From a094d965f6a7040f74d66da6a4147756a4fd7682 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 11:50:36 -0300 >Subject: [PATCH] Bug 24321: Clean /checkouts > >--- > Koha/Old/Checkout.pm | 29 ++++++++- > Koha/REST/V1/Checkouts.pm | 131 ++++++++++++++------------------------ > 2 files changed, 75 insertions(+), 85 deletions(-) > >diff --git a/Koha/Old/Checkout.pm b/Koha/Old/Checkout.pm >index d602a63602..f89feaefe0 100644 >--- a/Koha/Old/Checkout.pm >+++ b/Koha/Old/Checkout.pm >@@ -27,7 +27,7 @@ Koha::Old:Checkout - Koha checkout object for returned items > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =head3 item > >@@ -58,6 +58,33 @@ sub patron { > return Koha::Patron->_new_from_dbic( $patron_rs ); > } > >+=head3 to_api_mapping >+ >+This method returns the mapping for representing a Koha::Old::Checkout object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ issue_id => 'checkout_id', >+ borrowernumber => 'patron_id', >+ itemnumber => 'item_id', >+ date_due => 'due_date', >+ branchcode => 'library_id', >+ returndate => 'checkin_date', >+ lastreneweddate => 'last_renewed_date', >+ issuedate => 'checkout_date', >+ notedate => 'note_date', >+ }; >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ > sub _type { > return 'OldIssue'; > } >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index c8ded14ef7..6246f9d081 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -45,16 +45,61 @@ List Koha::Checkout objects > > sub list { > my $c = shift->openapi->valid_input or return; >+ > my $checked_in = $c->validation->param('checked_in'); >+ > try { > my $checkouts_set; >+ > if ( $checked_in ) { > $checkouts_set = Koha::Old::Checkouts->new; > } else { > $checkouts_set = Koha::Checkouts->new; > } >- my $checkouts = $c->objects->search( $checkouts_set, \&_to_model, \&_to_api ); >- return $c->render( status => 200, openapi => $checkouts ); >+ >+ my $args = $c->validation->output; >+ my $attributes = {}; >+ >+ # Extract reserved params >+ my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($args); >+ >+ # Merge sorting into query attributes >+ $c->dbic_merge_sorting( >+ { >+ attributes => $attributes, >+ params => $reserved_params, >+ result_set => $checkouts_set >+ } >+ ); >+ >+ # Merge pagination into query attributes >+ $c->dbic_merge_pagination( >+ { >+ filter => $attributes, >+ params => $reserved_params >+ } >+ ); >+ >+ # Call the to_model function by reference, if defined >+ if ( defined $filtered_params ) { >+ # remove checked_in >+ delete $filtered_params->{checked_in}; >+ # Apply the mapping function to the passed params >+ $filtered_params = $checkouts_set->attributes_from_api($filtered_params); >+ $filtered_params = $c->build_query_params( $filtered_params, $reserved_params ); >+ } >+ >+ # Perform search >+ my $checkouts = $checkouts_set->search( $filtered_params, $attributes ); >+ >+ if ($checkouts->is_paged) { >+ $c->add_pagination_headers({ >+ total => $checkouts->pager->total_entries, >+ params => $args, >+ }); >+ } >+ >+ return $c->render( status => 200, openapi => $checkouts->to_api ); > } catch { > if ( $_->isa('DBIx::Class::Exception') ) { > return $c->render( >@@ -182,86 +227,4 @@ sub allows_renewal { > ); > } > >-=head3 _to_api >- >-Helper function that maps a hashref of Koha::Checkout attributes into REST api >-attribute names. >- >-=cut >- >-sub _to_api { >- my $checkout = shift; >- >- foreach my $column ( keys %{ $Koha::REST::V1::Checkouts::to_api_mapping } ) { >- my $mapped_column = $Koha::REST::V1::Checkouts::to_api_mapping->{$column}; >- if ( exists $checkout->{ $column } && defined $mapped_column ) >- { >- $checkout->{ $mapped_column } = delete $checkout->{ $column }; >- } >- elsif ( exists $checkout->{ $column } && !defined $mapped_column ) { >- delete $checkout->{ $column }; >- } >- } >- return $checkout; >-} >- >-=head3 _to_model >- >-Helper function that maps REST api objects into Koha::Checkouts >-attribute names. >- >-=cut >- >-sub _to_model { >- my $checkout = shift; >- >- foreach my $attribute ( keys %{ $Koha::REST::V1::Checkouts::to_model_mapping } ) { >- my $mapped_attribute = $Koha::REST::V1::Checkouts::to_model_mapping->{$attribute}; >- if ( exists $checkout->{ $attribute } && defined $mapped_attribute ) >- { >- $checkout->{ $mapped_attribute } = delete $checkout->{ $attribute }; >- } >- elsif ( exists $checkout->{ $attribute } && !defined $mapped_attribute ) >- { >- delete $checkout->{ $attribute }; >- } >- } >- return $checkout; >-} >- >-=head2 Global variables >- >-=head3 $to_api_mapping >- >-=cut >- >-our $to_api_mapping = { >- issue_id => 'checkout_id', >- borrowernumber => 'patron_id', >- itemnumber => 'item_id', >- date_due => 'due_date', >- branchcode => 'library_id', >- returndate => 'checkin_date', >- lastreneweddate => 'last_renewed_date', >- issuedate => 'checkout_date', >- notedate => 'note_date', >-}; >- >-=head3 $to_model_mapping >- >-=cut >- >-our $to_model_mapping = { >- checkout_id => 'issue_id', >- patron_id => 'borrowernumber', >- item_id => 'itemnumber', >- due_date => 'date_due', >- library_id => 'branchcode', >- checkin_date => 'returndate', >- last_renewed_date => 'lastreneweddate', >- checkout_date => 'issuedate', >- note_date => 'notedate', >- checked_in => undef, >-}; >- > 1; >-- >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