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

(-)a/Koha/Biblio.pm (+23 lines)
Lines 724-729 sub custom_cover_image_url { Link Here
724
    return $url;
724
    return $url;
725
}
725
}
726
726
727
=head3 to_api
728
729
    my $json = $biblio->to_api;
730
731
Overloaded method that returns a JSON representation of the Koha::Biblio object,
732
suitable for API output. The related Koha::Biblioitem object is merged as expected
733
on the API.
734
735
=cut
736
737
sub to_api {
738
    my ($self, $args) = @_;
739
740
    my $response = $self->SUPER::to_api( $args );
741
    my $biblioitem = $self->biblioitem->to_api( $args );
742
743
    foreach my $key ( keys %{ $biblioitem } ) {
744
        $response->{$key} = $biblioitem->{$key};
745
    }
746
747
    return $response;
748
}
749
727
=head3 to_api_mapping
750
=head3 to_api_mapping
728
751
729
This method returns the mapping for representing a Koha::Biblio object
752
This method returns the mapping for representing a Koha::Biblio object
(-)a/Koha/Biblioitem.pm (+1 lines)
Lines 41-46 on the API. Link Here
41
sub to_api_mapping {
41
sub to_api_mapping {
42
    return {
42
    return {
43
        agerestriction   => 'age_restriction',
43
        agerestriction   => 'age_restriction',
44
        biblionumber     => 'biblio_id',
44
        biblioitemnumber => undef, # meaningless
45
        biblioitemnumber => undef, # meaningless
45
        collectionissn   => 'collection_issn',
46
        collectionissn   => 'collection_issn',
46
        collectiontitle  => 'collection_title',
47
        collectiontitle  => 'collection_title',
(-)a/Koha/REST/V1/Biblios.pm (-25 / +1 lines)
Lines 59-65 sub get { Link Here
59
        if ( $c->req->headers->accept =~ m/application\/json/ ) {
59
        if ( $c->req->headers->accept =~ m/application\/json/ ) {
60
            return $c->render(
60
            return $c->render(
61
                status => 200,
61
                status => 200,
62
                json   => $c->build_json_biblio( { biblio => $biblio } )
62
                json   => $biblio->to_api
63
            );
63
            );
64
        }
64
        }
65
        else {
65
        else {
Lines 148-174 sub delete { Link Here
148
    };
148
    };
149
}
149
}
150
150
151
=head2 Internal methods
152
153
=head3 build_json_biblio
154
155
Internal method that returns all the attributes from the biblio and biblioitems tables
156
157
=cut
158
159
sub build_json_biblio {
160
    my ( $c, $args ) = @_;
161
162
    my $biblio = $args->{biblio};
163
164
    my $response = $biblio->to_api;
165
    my $biblioitem = $biblio->biblioitem->to_api;
166
167
    foreach my $key ( keys %{ $biblioitem } ) {
168
        $response->{$key} = $biblioitem->{$key};
169
    }
170
171
    return $response;
172
}
173
174
1;
151
1;
175
- 

Return to bug 24366