Bugzilla – Attachment 94592 Details for
Bug 23843
Make existing endpoints use Koha::Object(s)->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23843: Add mapping to Koha::Library
Bug-23843-Add-mapping-to-KohaLibrary.patch (text/plain), 3.54 KB, created by
Tomás Cohen Arazi (tcohen)
on 2019-10-22 19:01:50 UTC
(
hide
)
Description:
Bug 23843: Add mapping to Koha::Library
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2019-10-22 19:01:50 UTC
Size:
3.54 KB
patch
obsolete
>From 8a1c50d84b37e0bb85b461217f568c39d02a2d83 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 21 Oct 2019 13:26:57 -0300 >Subject: [PATCH] Bug 23843: Add mapping to Koha::Library > >This patch adds a to_api_mapping method to the class. This in effect >enables calling ->to_api on the object. The mapping is borrowed from the >API controller. It is not removed from the controller so we are able to >verify (through the tests) that there is no behavior change. >Once this is pushed we need to implement the counter-wise methods and >clean the controllers. >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/api/v1/libraries.t >=> SUCCESS: Tests pass >2. Apply this patch >3. Repeat (1) >=> SUCCESS: Tests still pass! >4. Sign off :-D > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Library.pm | 32 ++++++++++++++++++++++++++++++++ > Koha/REST/V1/Library.pm | 16 +++++++++++++--- > 2 files changed, 45 insertions(+), 3 deletions(-) > >diff --git a/Koha/Library.pm b/Koha/Library.pm >index 6870e84cc4..dab86e7580 100644 >--- a/Koha/Library.pm >+++ b/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 >diff --git a/Koha/REST/V1/Library.pm b/Koha/REST/V1/Library.pm >index 0bf16ee60b..a40e049331 100644 >--- a/Koha/REST/V1/Library.pm >+++ b/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') ) { >-- >2.23.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 23843
:
94470
|
94471
|
94472
|
94473
|
94474
|
94475
|
94476
|
94477
|
94478
|
94496
|
94506
|
94507
|
94508
|
94509
|
94510
|
94511
|
94512
|
94513
|
94514
|
94587
|
94588
|
94589
|
94590
|
94591
|
94592
|
94593
|
94594
|
94595
|
94596
|
94619
|
94620
|
94621
|
94622
|
94623
|
94624
|
94625
|
94626
|
94627
|
94628