Bugzilla – Attachment 78435 Details for
Bug 18731
Add routes for acquisition orders
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18731: /acquisitions/orders endpoint
Bug-18731-acquisitionsorders-endpoint.patch (text/plain), 11.05 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-09-05 11:53:20 UTC
(
hide
)
Description:
Bug 18731: /acquisitions/orders endpoint
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-09-05 11:53:20 UTC
Size:
11.05 KB
patch
obsolete
>From af47e6f4fd618505a538d790a79fe88c620c8f12 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 5 Sep 2017 16:44:43 -0300 >Subject: [PATCH] Bug 18731: /acquisitions/orders endpoint > >This patches implement the /acquisitions/orders endpoint. >It uses the new pagination, query parsing and object searching plugins. > >The attribute names are consistent with the voted RFC > >Sponsored-by: Camden County >--- > Koha/REST/V1/Acquisitions/Orders.pm | 308 ++++++++++++++++++++++++++++ > Koha/Schema/Result/Aqorder.pm | 3 + > 2 files changed, 311 insertions(+) > create mode 100644 Koha/REST/V1/Acquisitions/Orders.pm > >diff --git a/Koha/REST/V1/Acquisitions/Orders.pm b/Koha/REST/V1/Acquisitions/Orders.pm >new file mode 100644 >index 0000000000..e2aba7b48f >--- /dev/null >+++ b/Koha/REST/V1/Acquisitions/Orders.pm >@@ -0,0 +1,308 @@ >+package Koha::REST::V1::Acquisitions::Orders; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use Mojo::Base 'Mojolicious::Controller'; >+ >+use Koha::Acquisition::Orders; >+ >+use Try::Tiny; >+ >+sub list { >+ >+ my $c = shift->openapi->valid_input or return; >+ >+ return try { >+ my $orders = $c->objects->search( Koha::Acquisition::Orders->new, \&_to_model, \&_to_api ); >+ >+ return $c->render( >+ status => 200, >+ openapi => $orders >+ ); >+ } >+ catch { >+ if ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => $_->{msg} } >+ ); >+ } >+ else { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check the logs." } >+ ); >+ } >+ }; >+} >+ >+sub get { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') ); >+ >+ unless ($order) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Order not found" } >+ ); >+ } >+ >+ return $c->render( >+ status => 200, >+ openapi => _to_api( $order->TO_JSON ) >+ ); >+} >+ >+sub add { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $order = Koha::Acquisition::Order->new( _to_model($c->validation->param('body')) ); >+ >+ return try { >+ $order->store; >+ return $c->render( >+ status => 200, >+ openapi => $order >+ ); >+ } >+ catch { >+ if ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => $_->msg } >+ ); >+ } >+ else { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check the logs." } >+ ); >+ } >+ }; >+} >+ >+sub update { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $order; >+ >+ return try { >+ $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') ); >+ $order->set( _to_model($c->validation->param('body')) ); >+ $order->store(); >+ return $c->render( >+ status => 200, >+ openapi => _to_api( $order->TO_JSON ) >+ ); >+ } >+ catch { >+ if ( not defined $order ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ elsif ( $_->isa('Koha::Exceptions::Object') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => $_->message } >+ ); >+ } >+ else { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check the logs." } >+ ); >+ } >+ }; >+} >+ >+sub delete { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $order; >+ >+ return try { >+ $order = Koha::Acquisition::Orders->find( $c->validation->param('order_id') ); >+ $order->delete; >+ return $c->render( >+ status => 200, >+ openapi => q{} >+ ); >+ } >+ catch { >+ if ( not defined $order ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Object not found" } >+ ); >+ } >+ elsif ( $_->isa('DBIx::Class::Exception') ) { >+ return $c->render( >+ status => 500, >+ openapi => { error => $_->msg } >+ ); >+ } >+ else { >+ return $c->render( >+ status => 500, >+ openapi => { error => "Something went wrong, check the logs." } >+ ); >+ } >+ }; >+} >+ >+=head3 _to_api >+ >+Helper function that maps unblessed Koha::Acquisition::Order objects into REST api >+attribute names. >+ >+=cut >+ >+sub _to_api { >+ my $order = shift; >+ >+ # Rename attributes >+ foreach my $column ( keys %{ $Koha::REST::V1::Acquisitions::Orders::to_api_mapping } ) { >+ my $mapped_column = $Koha::REST::V1::Acquisitions::Orders::to_api_mapping->{$column}; >+ if ( exists $order->{ $column } >+ && defined $mapped_column ) >+ { >+ # key != undef >+ $order->{ $mapped_column } = delete $order->{ $column }; >+ } >+ elsif ( exists $order->{ $column } >+ && !defined $mapped_column ) >+ { >+ # key == undef >+ delete $order->{ $column }; >+ } >+ } >+ >+ return $order; >+} >+ >+=head3 _to_model >+ >+Helper function that maps REST api objects into Koha::Acquisition::Order >+attribute names. >+ >+=cut >+ >+sub _to_model { >+ my $order = shift; >+ >+ foreach my $attribute ( keys %{ $Koha::REST::V1::Acquisitions::Orders::to_model_mapping } ) { >+ my $mapped_attribute = $Koha::REST::V1::Acquisitions::Orders::to_model_mapping->{$attribute}; >+ if ( exists $order->{ $attribute } >+ && defined $mapped_attribute ) >+ { >+ # key => !undef >+ $order->{ $mapped_attribute } = delete $order->{ $attribute }; >+ } >+ elsif ( exists $order->{ $attribute } >+ && !defined $mapped_attribute ) >+ { >+ # key => undef / to be deleted >+ delete $order->{ $attribute }; >+ } >+ } >+ >+ return $order; >+} >+ >+=head2 Global variables >+ >+=head3 $to_api_mapping >+ >+=cut >+ >+our $to_api_mapping = { >+ basketno => 'basket_id', >+ biblionumber => 'biblio_id', >+ budgetdate => undef, # unused >+ cancellationreason => 'cancellation_reason', >+ claimed_date => 'last_claim_date', >+ datecacellationprinted => 'cancellation_date', >+ datereceived => 'date_received', >+ discount => 'discount_rate', >+ entrydate => 'entry_date', >+ freight => 'shipping_cost', >+ invoiceid => 'invoice_id', >+ line_item_id => undef, # EDIFACT related >+ listprice => 'list_price', >+ order_internalnote => 'internal_note', >+ order_vendornote => 'vendor_note', >+ ordernumber => 'order_id', >+ orderstatus => 'status', >+ parent_ordernumber => 'parent_order_id', >+ purchaseordernumber => undef, # obsolete >+ quantityreceived => 'quantity_received', >+ sort1 => 'statistics_1', >+ sort1_authcat => 'statistics_1_authcat', >+ sort2 => 'statistics_2', >+ sort2_authcat => 'statistics_2_authcat', >+ subscriptionid => 'subscription_id', >+ suppliers_reference_number => undef, # EDIFACT related >+ suppliers_reference_qualifier => undef, # EDIFACT related >+ suppliers_report => undef, # EDIFACT related >+ tax_rate_bak => undef, # unused >+ tax_value_bak => undef, # unused >+ uncertainprice => 'uncertain_price', >+ unitprice => 'unit_price', >+ unitprice_tax_excluded => 'unit_price_tax_excluded', >+ unitprice_tax_included => 'unit_price_tax_included' >+}; >+ >+ >+=head3 $to_model_mapping >+ >+=cut >+ >+our $to_model_mapping = { >+ basket_id => 'basketno', >+ biblio_id => 'biblionumber', >+ last_claim_date => 'claimed_date', >+ cancellation_date => 'datecacellationprinted', >+ discount_rate => 'discount', >+ cancellation_reason => 'cancellationreason', >+ date_received => 'datereceived', >+ entry_date => 'entrydate', >+ shipping_cost => 'freight', >+ invoice_id => 'invoiceid', >+ list_price => 'listprice', >+ internal_note => 'order_internalnote', >+ vendor_note => 'order_vendornote', >+ order_id => 'ordernumber', >+ status => 'orderstatus', >+ parent_order_id => 'parent_ordernumber', >+ quantity_received => 'quantityreceived', >+ statistics_1 => 'sort1', >+ statistics_1_authcat => 'sort1_authcat', >+ statistics_2 => 'sort2', >+ statistics_2_authcat => 'sort2_authcat', >+ subscription_id => 'subscriptionid', >+ uncertain_price => 'uncertainprice', >+ unit_price => 'unitprice', >+ unit_price_tax_excluded => 'unitprice_tax_excluded', >+ unit_price_tax_included => 'unitprice_tax_included' >+}; >+ >+ >+1; >diff --git a/Koha/Schema/Result/Aqorder.pm b/Koha/Schema/Result/Aqorder.pm >index f0dca06948..8af4872197 100644 >--- a/Koha/Schema/Result/Aqorder.pm >+++ b/Koha/Schema/Result/Aqorder.pm >@@ -664,6 +664,9 @@ __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber"); > # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-31 11:51:37 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GQEXetlivZm7buQohl8m4A > >+__PACKAGE__->add_columns( >+ '+uncertainprice' => { is_boolean => 1 } >+); > > # You can replace this text with custom code or comments, and it will be preserved on regeneration > 1; >-- >2.18.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 18731
:
69184
|
69185
|
69309
|
69310
|
69544
|
73959
|
73960
|
78435
|
78436
|
84133
|
84134
|
95054
|
95055
|
95056
|
96853
|
96854
|
96855
|
96856
|
96857
|
96858
|
96916
|
96917
|
96918
|
96938
|
96961
|
96962
|
96963
|
96964
|
96965
|
96966
|
97107
|
97108
|
97109
|
97110
|
97111
|
97112
|
97113
|
97331