@@ -, +, @@ $ kshell k$ prove t/db_dependent/api/v1/acquisitions_vendors.t --- Koha/Acquisition/Bookseller.pm | 24 ++++++++++++++++++++++- Koha/REST/V1/Acquisitions/Vendors.pm | 29 ++++++++++++++++------------ 2 files changed, 40 insertions(+), 13 deletions(-) --- a/Koha/Acquisition/Bookseller.pm +++ a/Koha/Acquisition/Bookseller.pm @@ -28,7 +28,7 @@ Koha::Acquisition::Bookseller Object class =head1 API -=head2 Class Methods +=head2 Class methods =head3 baskets @@ -73,6 +73,28 @@ sub subscriptions { return Koha::Subscriptions->search( { aqbooksellerid => $self->id } ); } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Acquisition::Bookseller object +on the API. + +=cut + +sub to_api_mapping { + return { + booksellerfax => undef, + bookselleremail => undef, + booksellerurl => undef, + currency => undef, + othersupplier => undef, + listprice => 'list_currency', + invoiceprice => 'invoice_currency', + gstreg => 'gst', + listincgst => 'list_includes_gst', + invoiceincgst => 'invoice_includes_gst' + }; +} + =head2 Internal methods =head3 _type --- a/Koha/REST/V1/Acquisitions/Vendors.pm +++ a/Koha/REST/V1/Acquisitions/Vendors.pm @@ -48,13 +48,12 @@ sub list_vendors { if $args->{$filter_param}; } - my @vendors; - return try { - @vendors = Koha::Acquisition::Booksellers->search($filter); - @vendors = map { _to_api($_->TO_JSON) } @vendors; - return $c->render( status => 200, - openapi => \@vendors ); + my $vendors = Koha::Acquisition::Booksellers->search($filter); + return $c->render( + status => 200, + openapi => $vendors->to_api + ); } catch { if ( $_->isa('DBIx::Class::Exception') ) { @@ -83,8 +82,10 @@ sub get_vendor { openapi => { error => "Vendor not found" } ); } - return $c->render( status => 200, - openapi => _to_api($vendor->TO_JSON) ); + return $c->render( + status => 200, + openapi => $vendor->to_api + ); } =head3 add_vendor @@ -100,8 +101,10 @@ sub add_vendor { return try { $vendor->store; - return $c->render( status => 200, - openapi => _to_api($vendor->TO_JSON) ); + return $c->render( + status => 200, + openapi => $vendor->to_api + ); } catch { if ( $_->isa('DBIx::Class::Exception') ) { @@ -130,8 +133,10 @@ sub update_vendor { $vendor = Koha::Acquisition::Booksellers->find( $c->validation->param('vendor_id') ); $vendor->set( _to_model( $c->validation->param('body') ) ); $vendor->store(); - return $c->render( status => 200, - openapi => _to_api($vendor->TO_JSON) ); + return $c->render( + status => 200, + openapi => $vendor->to_api + ); } catch { if ( not defined $vendor ) { --