Bugzilla – Attachment 96716 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 /acquisitions/vendors
Bug-24321-Clean-acquisitionsvendors.patch (text/plain), 7.28 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-12-31 14:57:35 UTC
(
hide
)
Description:
Bug 24321: Clean /acquisitions/vendors
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-12-31 14:57:35 UTC
Size:
7.28 KB
patch
obsolete
>From 9f5543886c09a1bfe8e793e9143d7343f5ebf102 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 10:50:15 -0300 >Subject: [PATCH] Bug 24321: Clean /acquisitions/vendors > >--- > Koha/REST/V1/Acquisitions/Vendors.pm | 84 ++++--------------- > .../swagger/paths/acquisitions_vendors.json | 18 ++-- > t/db_dependent/api/v1/acquisitions_vendors.t | 2 +- > 3 files changed, 29 insertions(+), 75 deletions(-) > >diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm >index 986b1ab8f6..0cb33fbf28 100644 >--- a/Koha/REST/V1/Acquisitions/Vendors.pm >+++ b/Koha/REST/V1/Acquisitions/Vendors.pm >@@ -31,28 +31,21 @@ Koha::REST::V1::Acquisitions::Vendors > > =head2 Methods > >-=head3 list_vendors >+=head3 list > > Controller function that handles listing Koha::Acquisition::Bookseller objects > > =cut > >-sub list_vendors { >+sub list { > 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}; >- } >- > return try { >- my $vendors = Koha::Acquisition::Booksellers->search($filter); >+ my $vendors_rs = Koha::Acquisition::Booksellers->new; >+ my $vendors = $c->objects->search( $vendors_rs ); > return $c->render( > status => 200, >- openapi => $vendors->to_api >+ openapi => $vendors > ); > } > catch { >@@ -67,13 +60,13 @@ sub list_vendors { > }; > } > >-=head3 get_vendor >+=head3 get > > Controller function that handles retrieving a single Koha::Acquisition::Bookseller > > =cut > >-sub get_vendor { >+sub get { > my $c = shift->openapi->valid_input or return; > > my $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') ); >@@ -88,16 +81,16 @@ sub get_vendor { > ); > } > >-=head3 add_vendor >+=head3 add > > Controller function that handles adding a new Koha::Acquisition::Bookseller object > > =cut > >-sub add_vendor { >+sub add { > my $c = shift->openapi->valid_input or return; > >- my $vendor = Koha::Acquisition::Bookseller->new( _to_model( $c->validation->param('body') ) ); >+ my $vendor = Koha::Acquisition::Bookseller->new_from_api( $c->validation->param('body') ); > > return try { > $vendor->store; >@@ -119,20 +112,20 @@ sub add_vendor { > }; > } > >-=head3 update_vendor >+=head3 update > > Controller function that handles updating a Koha::Acquisition::Bookseller object > > =cut > >-sub update_vendor { >+sub update { > my $c = shift->openapi->valid_input or return; > > my $vendor; > > return try { > $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') ); >- $vendor->set( _to_model( $c->validation->param('body') ) ); >+ $vendor->set_from_api( $c->validation->param('body') ); > $vendor->store(); > return $c->render( > status => 200, >@@ -156,13 +149,13 @@ sub update_vendor { > > } > >-=head3 delete_vendor >+=head3 delete > > Controller function that handles deleting a Koha::Acquisition::Bookseller object > > =cut > >-sub delete_vendor { >+sub delete { > my $c = shift->openapi->valid_input or return; > > my $vendor; >@@ -190,51 +183,4 @@ sub delete_vendor { > > } > >-=head3 _to_api >- >-Helper function that maps a Koha::Acquisition::Bookseller object into >-the attribute names the exposed REST api spec. >- >-=cut >- >-sub _to_api { >- my $vendor = shift; >- >- # Delete unused fields >- delete $vendor->{booksellerfax}; >- delete $vendor->{bookselleremail}; >- delete $vendor->{booksellerurl}; >- delete $vendor->{currency}; >- delete $vendor->{othersupplier}; >- >- # Rename changed fields >- $vendor->{list_currency} = delete $vendor->{listprice}; >- $vendor->{invoice_currency} = delete $vendor->{invoiceprice}; >- $vendor->{gst} = delete $vendor->{gstreg}; >- $vendor->{list_includes_gst} = delete $vendor->{listincgst}; >- $vendor->{invoice_includes_gst} = delete $vendor->{invoiceincgst}; >- >- return $vendor; >-} >- >-=head3 _to_model >- >-Helper function that maps REST api objects into Koha::Acquisition::Bookseller >-attribute names. >- >-=cut >- >-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}; >- >- return $vendor; >-} >- > 1; >diff --git a/api/v1/swagger/paths/acquisitions_vendors.json b/api/v1/swagger/paths/acquisitions_vendors.json >index f8da32f16a..02952318e1 100644 >--- a/api/v1/swagger/paths/acquisitions_vendors.json >+++ b/api/v1/swagger/paths/acquisitions_vendors.json >@@ -1,7 +1,7 @@ > { > "/acquisitions/vendors": { > "get": { >- "x-mojo-to": "Acquisitions::Vendors#list_vendors", >+ "x-mojo-to": "Acquisitions::Vendors#list", > "operationId": "listVendors", > "tags": ["acquisitions","vendors"], > "produces": [ >@@ -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": { >@@ -68,7 +76,7 @@ > } > }, > "post": { >- "x-mojo-to": "Acquisitions::Vendors#add_vendor", >+ "x-mojo-to": "Acquisitions::Vendors#add", > "operationId": "addVendor", > "tags": ["acquisitions","vendors"], > "parameters": [{ >@@ -130,7 +138,7 @@ > }, > "/acquisitions/vendors/{vendor_id}": { > "get": { >- "x-mojo-to": "Acquisitions::Vendors#get_vendor", >+ "x-mojo-to": "Acquisitions::Vendors#get", > "operationId": "getVendor", > "tags": ["acquisitions","vendors"], > "parameters": [{ >@@ -184,7 +192,7 @@ > } > }, > "put": { >- "x-mojo-to": "Acquisitions::Vendors#update_vendor", >+ "x-mojo-to": "Acquisitions::Vendors#update", > "operationId": "updateVendor", > "tags": ["acquisitions","vendors"], > "parameters": [{ >@@ -246,7 +254,7 @@ > } > }, > "delete": { >- "x-mojo-to": "Acquisitions::Vendors#delete_vendor", >+ "x-mojo-to": "Acquisitions::Vendors#delete", > "operationId": "deleteVendor", > "tags": ["acquisitions","vendors"], > "parameters": [{ >diff --git a/t/db_dependent/api/v1/acquisitions_vendors.t b/t/db_dependent/api/v1/acquisitions_vendors.t >index 5ae7367de3..c3ec28728d 100644 >--- a/t/db_dependent/api/v1/acquisitions_vendors.t >+++ b/t/db_dependent/api/v1/acquisitions_vendors.t >@@ -156,7 +156,7 @@ subtest 'get() test' => sub { > $tx->req->env( { REMOTE_ADDR => $remote_address } ); > $t->request_ok($tx) > ->status_is(200) >- ->json_is( Koha::REST::V1::Acquisitions::Vendors::_to_api( $vendor->TO_JSON ) ); >+ ->json_is( $vendor->to_api ); > > my $non_existent_id = $vendor->id + 1; > $tx = $t->ua->build_tx( GET => "/api/v1/acquisitions/vendors/" . $non_existent_id ); >-- >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