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: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
c46c86b3e7
commit
09bfdddc7a
|
|
@ -1569,6 +1569,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
|
||||
|
|
|
|||
|
|
@ -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') ) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue