View | Details | Raw Unified | Return to bug 23843
Collapse All | Expand All

(-)a/Koha/Patron.pm (+84 lines)
Lines 1476-1481 sub add_guarantor { Link Here
1476
    )->store();
1476
    )->store();
1477
}
1477
}
1478
1478
1479
=head3 to_api
1480
1481
    my $json = $patron->to_api;
1482
1483
Overloaded method that returns a JSON representation of the Koha::Patron object,
1484
suitable for API output.
1485
1486
=cut
1487
1488
sub to_api {
1489
    my ( $self ) = @_;
1490
1491
    my $json_patron = $self->SUPER::to_api;
1492
1493
    $json_patron->{restricted} = ( $self->is_debarred )
1494
                                    ? Mojo::JSON->true
1495
                                    : Mojo::JSON->false;
1496
1497
    return $json_patron;
1498
}
1499
1500
=head3 to_api_mapping
1501
1502
This method returns the mapping for representing a Koha::Patron object
1503
on the API.
1504
1505
=cut
1506
1507
sub to_api_mapping {
1508
    return {
1509
        borrowernotes       => 'staff_notes',
1510
        borrowernumber      => 'patron_id',
1511
        branchcode          => 'library_id',
1512
        categorycode        => 'category_id',
1513
        checkprevcheckout   => 'check_previous_checkout',
1514
        contactfirstname    => undef,                     # Unused
1515
        contactname         => undef,                     # Unused
1516
        contactnote         => 'altaddress_notes',
1517
        contacttitle        => undef,                     # Unused
1518
        dateenrolled        => 'date_enrolled',
1519
        dateexpiry          => 'expiry_date',
1520
        dateofbirth         => 'date_of_birth',
1521
        debarred            => undef,                     # replaced by 'restricted'
1522
        debarredcomment     => undef,    # calculated, API consumers will use /restrictions instead
1523
        emailpro            => 'secondary_email',
1524
        flags               => undef,    # permissions manipulation handled in /permissions
1525
        gonenoaddress       => 'incorrect_address',
1526
        guarantorid         => 'guarantor_id',
1527
        lastseen            => 'last_seen',
1528
        lost                => 'patron_card_lost',
1529
        opacnote            => 'opac_notes',
1530
        othernames          => 'other_name',
1531
        password            => undef,            # password manipulation handled in /password
1532
        phonepro            => 'secondary_phone',
1533
        relationship        => 'relationship_type',
1534
        sex                 => 'gender',
1535
        smsalertnumber      => 'sms_number',
1536
        sort1               => 'statistics_1',
1537
        sort2               => 'statistics_2',
1538
        streetnumber        => 'street_number',
1539
        streettype          => 'street_type',
1540
        zipcode             => 'postal_code',
1541
        B_address           => 'altaddress_address',
1542
        B_address2          => 'altaddress_address2',
1543
        B_city              => 'altaddress_city',
1544
        B_country           => 'altaddress_country',
1545
        B_email             => 'altaddress_email',
1546
        B_phone             => 'altaddress_phone',
1547
        B_state             => 'altaddress_state',
1548
        B_streetnumber      => 'altaddress_street_number',
1549
        B_streettype        => 'altaddress_street_type',
1550
        B_zipcode           => 'altaddress_postal_code',
1551
        altcontactaddress1  => 'altcontact_address',
1552
        altcontactaddress2  => 'altcontact_address2',
1553
        altcontactaddress3  => 'altcontact_city',
1554
        altcontactcountry   => 'altcontact_country',
1555
        altcontactfirstname => 'altcontact_firstname',
1556
        altcontactphone     => 'altcontact_phone',
1557
        altcontactsurname   => 'altcontact_surname',
1558
        altcontactstate     => 'altcontact_state',
1559
        altcontactzipcode   => 'altcontact_postal_code'
1560
    };
1561
}
1562
1479
=head2 Internal methods
1563
=head2 Internal methods
1480
1564
1481
=head3 _type
1565
=head3 _type
(-)a/Koha/REST/V1/Patrons.pm (-7 / +4 lines)
Lines 73-81 sub list { Link Here
73
                }
73
                }
74
            );
74
            );
75
        }
75
        }
76
        my @patrons = $patrons->as_list;
76
77
        @patrons = map { _to_api( $_->TO_JSON ) } @patrons;
77
        return $c->render( status => 200, openapi => $patrons->to_api );
78
        return $c->render( status => 200, openapi => \@patrons );
79
    }
78
    }
80
    catch {
79
    catch {
81
        if ( $_->isa('DBIx::Class::Exception') ) {
80
        if ( $_->isa('DBIx::Class::Exception') ) {
Lines 110-116 sub get { Link Here
110
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
109
        return $c->render( status => 404, openapi => { error => "Patron not found." } );
111
    }
110
    }
112
111
113
    return $c->render( status => 200, openapi => _to_api( $patron->TO_JSON ) );
112
    return $c->render( status => 200, openapi => $patron->to_api );
114
}
113
}
115
114
116
=head3 add
115
=head3 add
Lines 127-135 sub add { Link Here
127
        my $body = _to_model( $c->validation->param('body') );
126
        my $body = _to_model( $c->validation->param('body') );
128
127
129
        my $patron = Koha::Patron->new( _to_model($body) )->store;
128
        my $patron = Koha::Patron->new( _to_model($body) )->store;
130
        $patron    = _to_api( $patron->TO_JSON );
131
129
132
        return $c->render( status => 201, openapi => $patron );
130
        return $c->render( status => 201, openapi => $patron->to_api );
133
    }
131
    }
134
    catch {
132
    catch {
135
        unless ( blessed $_ && $_->can('rethrow') ) {
133
        unless ( blessed $_ && $_->can('rethrow') ) {
136
- 

Return to bug 23843