Bugzilla – Attachment 96924 Details for
Bug 23893
Add ->new_from_api and ->set_from_api methods to Koha::Object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23893: Use in /patrons
Bug-23893-Use-in-patrons.patch (text/plain), 2.67 KB, created by
Kyle M Hall (khall)
on 2020-01-07 18:03:10 UTC
(
hide
)
Description:
Bug 23893: Use in /patrons
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-01-07 18:03:10 UTC
Size:
2.67 KB
patch
obsolete
>From eb68eed69c23ccb482627fd491d9d1bce8d7d3e3 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 12 Nov 2019 10:00:14 -0300 >Subject: [PATCH] Bug 23893: Use in /patrons > >This patch makes the patrons endpoint use the new methods from >Koha::Object. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/api/v1/patrons.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: John Doe <you@example.com> >--- > Koha/Patron.pm | 24 ++++++++++++++++++++++++ > Koha/REST/V1/Patrons.pm | 9 +++------ > 2 files changed, 27 insertions(+), 6 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 27e552a48c..b574b5f32b 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1565,6 +1565,30 @@ sub to_api { > return $json_patron; > } > >+sub attributes_from_api { >+ my ( $self, $attrs ) = @_; >+ >+ $attrs = $self->SUPER::attributes_from_api( $attrs ); >+ >+ if ( exists $attrs->{lost} ) { >+ $attrs->{lost} = ($attrs->{lost}) ? 1 : 0; >+ } >+ >+ if ( exists $attrs->{ gonenoaddress} ) { >+ $attrs->{gonenoaddress} = ($attrs->{gonenoaddress}) ? 1 : 0; >+ } >+ >+ if ( exists $attrs->{lastseen} ) { >+ $attrs->{lastseen} = output_pref({ str => $attrs->{lastseen}, dateformat => 'sql' }); >+ } >+ >+ if ( exists $attrs->{updated_on} ) { >+ $attrs->{updated_on} = output_pref({ str => $attrs->{updated_on}, dateformat => 'sql' }); >+ } >+ >+ return $attrs; >+} >+ > =head3 to_api_mapping > > This method returns the mapping for representing a Koha::Patron object >diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm >index dfd5cb3486..ecfbcf117e 100644 >--- a/Koha/REST/V1/Patrons.pm >+++ b/Koha/REST/V1/Patrons.pm >@@ -123,9 +123,7 @@ sub add { > > return try { > >- my $body = _to_model( $c->validation->param('body') ); >- >- my $patron = Koha::Patron->new( _to_model($body) )->store; >+ my $patron = Koha::Patron->new_from_api( $c->validation->param('body') )->store; > > $c->res->headers->location( $c->req->url->to_string . '/' . $patron->borrowernumber ); > return $c->render( >@@ -196,11 +194,10 @@ sub update { > } > > return try { >- my $body = _to_model($c->validation->param('body')); > >- $patron->set($body)->store; >+ $patron->set_from_api($c->validation->param('body'))->store; > $patron->discard_changes; >- return $c->render( status => 200, openapi => $patron ); >+ return $c->render( status => 200, openapi => $patron->to_api ); > } > catch { > unless ( blessed $_ && $_->can('rethrow') ) { >-- >2.21.0 (Apple Git-122.2)
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 23893
:
95276
|
95277
|
95278
|
95311
|
95312
|
95313
|
95314
|
95315
|
96126
|
96127
|
96128
|
96129
|
96130
|
96652
|
96655
|
96656
|
96657
|
96658
|
96659
|
96660
|
96661
|
96662
|
96665
|
96666
|
96920
|
96921
|
96922
|
96923
|
96924
|
96925
|
96926
|
96927
|
96928
|
96929
|
96930
|
96931
|
96932
|
96933
|
96934
|
96935
|
96936
|
96937
|
97391