Bugzilla – Attachment 69317 Details for
Bug 19250
Add pagination to /acquisitions/vendors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19250: Add /acquisitions/vendors pagination
Bug-19250-Add-acquisitionsvendors-pagination.patch (text/plain), 3.38 KB, created by
Tomás Cohen Arazi (tcohen)
on 2017-11-23 20:27:03 UTC
(
hide
)
Description:
Bug 19250: Add /acquisitions/vendors pagination
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2017-11-23 20:27:03 UTC
Size:
3.38 KB
patch
obsolete
>From 923e410e7b347445814eb532c85a60d3be2f227e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 23 Nov 2017 16:44:54 -0300 >Subject: [PATCH] Bug 19250: Add /acquisitions/vendors pagination > >This patch makes the /acquisitions/vendors endpoint paginated and handle >the new special params introduced by 19410: _match, _order_by_, _page >and _per_page. > >To do so, the OpenAPI spec is updated with the new parameters, and >_to_model is rewritten to avoid autovivification, as required by the >extension of the objects.search helper, introduced by bug 19686. >--- > Koha/REST/V1/Acquisitions/Vendors.pm | 31 +++++++++++++------------- > api/v1/swagger/paths/acquisitions_vendors.json | 8 +++++++ > 2 files changed, 24 insertions(+), 15 deletions(-) > >diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm >index 5f86ac82d4..7c55cf3589 100644 >--- a/Koha/REST/V1/Acquisitions/Vendors.pm >+++ b/Koha/REST/V1/Acquisitions/Vendors.pm >@@ -38,20 +38,14 @@ Controller function that handles listing Koha::Acquisition::Bookseller objects > =cut > > sub list_vendors { >- my $c = shift->openapi->valid_input or return; >- >- my $args = _to_model($c->req->params->to_hash); >- my $filter; > >- for my $filter_param ( keys %$args ) { >- $filter->{$filter_param} = { LIKE => $args->{$filter_param} . "%" } >- if $args->{$filter_param}; >- } >+ my $c = shift->openapi->valid_input or return; > > my @vendors; > > return try { >- @vendors = Koha::Acquisition::Booksellers->search($filter); >+ my $vendors_set = Koha::Acquisition::Booksellers->new; >+ @vendors = $c->objects->search( $vendors_set, \&_to_model )->as_list; > @vendors = map { _to_api($_->TO_JSON) } @vendors; > return $c->render( status => 200, > openapi => \@vendors ); >@@ -221,12 +215,19 @@ attribute names. > sub _to_model { > my $vendor = shift; > >- # Rename back >- $vendor->{listprice} = delete $vendor->{list_currency}; >- $vendor->{invoiceprice} = delete $vendor->{invoice_currency}; >- $vendor->{gstreg} = delete $vendor->{gst}; >- $vendor->{listincgst} = delete $vendor->{list_includes_gst}; >- $vendor->{invoiceincgst} = delete $vendor->{invoice_includes_gst}; >+ my $mapping = { >+ list_currency => 'listprice', >+ invoice_currency => 'invoiceprice', >+ gst => 'gstreg', >+ list_includes_gst => 'listincgst', >+ invoice_includes_gst => 'invoiceincgst' >+ }; >+ >+ foreach my $key ( keys %{ $mapping } ) { >+ if ( exists $vendor->{ $key } ) { >+ $vendor->{ $mapping->{$key} } = delete $vendor->{ $key }; >+ } >+ } > > return $vendor; > } >diff --git a/api/v1/swagger/paths/acquisitions_vendors.json b/api/v1/swagger/paths/acquisitions_vendors.json >index 4c86a8de87..64fd8dfe69 100644 >--- a/api/v1/swagger/paths/acquisitions_vendors.json >+++ b/api/v1/swagger/paths/acquisitions_vendors.json >@@ -19,6 +19,14 @@ > "description": "Case insensitive search on vendor's account number", > "required": false, > "type": "string" >+ }, { >+ "$ref": "../parameters.json#/match" >+ }, { >+ "$ref": "../parameters.json#/order_by" >+ }, { >+ "$ref": "../parameters.json#/page" >+ }, { >+ "$ref": "../parameters.json#/per_page" > }], > "responses": { > "200": { >-- >2.15.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 19250
: 69317