@@ -, +, @@ $ kshell k$ prove t/db_dependent/api/v1/libraries.t --- Koha/Library.pm | 32 ++++++++++++++++++++++++++++++++ Koha/REST/V1/Library.pm | 16 +++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) --- a/Koha/Library.pm +++ a/Koha/Library.pm @@ -89,6 +89,38 @@ sub cash_registers { return Koha::Cash::Registers->_new_from_dbic( $rs ); } +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::Library object +on the API. + +=cut + +sub to_api_mapping { + return { + branchcode => 'library_id', + branchname => 'name', + branchaddress1 => 'address1', + branchaddress2 => 'address2', + branchaddress3 => 'address3', + branchzip => 'postal_code', + branchcity => 'city', + branchstate => 'state', + branchcountry => 'country', + branchphone => 'phone', + branchfax => 'fax', + branchemail => 'email', + branchreplyto => 'reply_to_email', + branchreturnpath => 'return_path_email', + branchurl => 'url', + issuing => undef, + branchip => 'ip', + branchprinter => undef, + branchnotes => 'notes', + marcorgcode => 'marc_org_code', + }; +} + =head2 Internal methods =head3 _type --- a/Koha/REST/V1/Library.pm +++ a/Koha/REST/V1/Library.pm @@ -79,7 +79,10 @@ sub get { openapi => { error => "Library not found" } ); } - return $c->render( status => 200, openapi => _to_api( $library->TO_JSON ) ); + return $c->render( + status => 200, + openapi => $library->to_api + ); } =head3 add @@ -95,7 +98,11 @@ sub add { my $library = Koha::Library->new( _to_model( $c->validation->param('body') ) ); $library->store; $c->res->headers->location( $c->req->url->to_string . '/' . $library->branchcode ); - return $c->render( status => 201, openapi => _to_api( $library->TO_JSON ) ); + + return $c->render( + status => 201, + openapi => $library->to_api + ); } catch { unless ( blessed $_ && $_->can('rethrow') ) { @@ -141,7 +148,10 @@ sub update { my $params = $c->req->json; $library->set( _to_model($params) ); $library->store(); - return $c->render( status => 200, openapi => _to_api($library->TO_JSON) ); + return $c->render( + status => 200, + openapi => $library->to_api + ); } catch { unless ( blessed $_ && $_->can('rethrow') ) { --