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

(-)a/Koha/Old/Biblio.pm (+56 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use base qw(Koha::Object);
20
use base qw(Koha::Object);
21
21
22
use Koha::Old::Biblio::Metadatas;
22
use Koha::Old::Biblio::Metadatas;
23
use Koha::Old::Biblioitems;
23
24
24
=head1 NAME
25
=head1 NAME
25
26
Lines 74-79 sub record_schema { Link Here
74
    return $self->metadata->schema // C4::Context->preference("marcflavour");
75
    return $self->metadata->schema // C4::Context->preference("marcflavour");
75
}
76
}
76
77
78
=head3 biblioitem
79
80
my $field = $self->biblioitem
81
82
Returns the related Koha::Old::Biblioitem object for this Biblio object
83
84
=cut
85
86
sub biblioitem {
87
    my ($self) = @_;
88
    return Koha::Old::Biblioitems->find( { biblionumber => $self->biblionumber } );
89
}
90
91
=head3 to_api
92
93
    my $json = $deleted_biblio->to_api;
94
95
Overloaded method that returns a JSON representation of the Koha::Old::Biblio object,
96
suitable for API output. The related Koha::Old::Biblioitem object is merged as expected
97
on the API.
98
99
=cut
100
101
sub to_api {
102
    my ($self, $args) = @_;
103
104
    my $response = $self->SUPER::to_api( $args );
105
106
    $args = defined $args ? {%$args} : {};
107
    delete $args->{embed};
108
109
    my $biblioitem = $self->biblioitem->to_api( $args );
110
111
    return { %$response, %$biblioitem };
112
}
113
114
=head3 to_api_mapping
115
116
This method returns the mapping for representing a Koha::Old::Biblio object
117
on the API.
118
119
=cut
120
121
sub to_api_mapping {
122
    return {
123
        biblionumber     => 'biblio_id',
124
        frameworkcode    => 'framework_id',
125
        unititle         => 'uniform_title',
126
        seriestitle      => 'series_title',
127
        copyrightdate    => 'copyright_date',
128
        datecreated      => 'creation_date',
129
        deleted_on       => 'timestamp',
130
    };
131
}
132
77
133
78
=head2 Internal methods
134
=head2 Internal methods
79
135
(-)a/Koha/REST/V1/Biblios.pm (-2 / +8 lines)
Lines 806-813 sub list { Link Here
806
    my $deleted = $c->param('deleted');
806
    my $deleted = $c->param('deleted');
807
    $c->req->params->remove('deleted');
807
    $c->req->params->remove('deleted');
808
808
809
    my $rs = $deleted ? Koha::Old::Biblios->search() : Koha::Biblios->search( undef, { prefetch => \@prefetch } );
809
    my $biblios;
810
    my $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] );
810
    if( $deleted ){
811
        my $rs = Koha::Old::Biblios->search();
812
        $biblios = $c->objects->search_rs( $rs );
813
    } else {
814
        my $rs = Koha::Biblios->search( undef, { prefetch => \@prefetch } );
815
        $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] );
816
    }
811
817
812
    return try {
818
    return try {
813
819
(-)a/t/db_dependent/api/v1/biblios.t (-11 / +10 lines)
Lines 1700-1726 subtest 'list() tests' => sub { Link Here
1700
    DelBiblio( $biblio->id );
1700
    DelBiblio( $biblio->id );
1701
    DelBiblio( $biblio2->id );
1701
    DelBiblio( $biblio2->id );
1702
1702
1703
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" =>
1703
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" =>
1704
          { Accept => 'application/json', 'x-koha-query' => $search } )
1704
          { Accept => 'application/json' } )
1705
      ->status_is(200);
1705
      ->status_is(200);
1706
1706
1707
    $result = $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" =>
1707
    $result = $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" =>
1708
          { Accept => 'application/marcxml+xml', 'x-koha-query' => $search } )
1708
          { Accept => 'application/marcxml+xml' } )
1709
      ->status_is(200)->tx->res->body;
1709
      ->status_is(200)->tx->res->body;
1710
1710
1711
    $encoded_title  = Encode::encode( "UTF-8", $title_with_diacritics );
1711
    $encoded_title  = Encode::encode( "UTF-8", $title_with_diacritics );
1712
    like( $result, qr/\Q$encoded_title/, "The title is not double encoded" );
1712
    like( $result, qr/\Q$encoded_title/, "The title is not double encoded" );
1713
1713
1714
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" =>
1714
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" =>
1715
          { Accept => 'application/marc-in-json', 'x-koha-query' => $search } )
1715
          { Accept => 'application/marc-in-json' } )
1716
      ->status_is(200);
1716
      ->status_is(200);
1717
1717
1718
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" =>
1718
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" =>
1719
          { Accept => 'application/marc', 'x-koha-query' => $search } )
1719
          { Accept => 'application/marc' } )
1720
      ->status_is(200);
1720
      ->status_is(200);
1721
1721
1722
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" =>
1722
    $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" =>
1723
          { Accept => 'text/plain', 'x-koha-query' => $search } )
1723
          { Accept => 'text/plain' } )
1724
      ->status_is(200);
1724
      ->status_is(200);
1725
1725
1726
1726
1727
- 

Return to bug 33960