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

(-)a/Koha/REST/V1/Biblios.pm (+24 lines)
Lines 32-37 use Try::Tiny qw( catch try ); Link Here
32
32
33
=head2 Methods
33
=head2 Methods
34
34
35
=head3 list
36
37
Retrieves a list of biblios
38
39
=cut
40
41
sub list {
42
    my $c = shift->openapi->valid_input or return;
43
44
    return try {
45
46
        my $biblios_rs = Koha::Biblios->new->search(undef, { join => 'biblioitem' });
47
        my $biblios = $c->objects->search( $biblios_rs );
48
49
        return $c->render(
50
            status  => 200,
51
            openapi => $biblios,
52
        );
53
    }
54
    catch {
55
        $c->unhandled_exception($_);
56
    };
57
}
58
35
=head3 get
59
=head3 get
36
60
37
Controller function that handles retrieving a single biblio object
61
Controller function that handles retrieving a single biblio object
(-)a/api/v1/swagger/paths/biblios.yaml (+40 lines)
Lines 1-4 Link Here
1
---
1
---
2
"/biblios":
3
  get:
4
    x-mojo-to: Biblios#list
5
    operationId: listBiblios
6
    tags:
7
      - biblios
8
    summary: List biblios
9
    parameters:
10
      - $ref: "../swagger.yaml#/parameters/match"
11
      - $ref: "../swagger.yaml#/parameters/order_by"
12
      - $ref: "../swagger.yaml#/parameters/page"
13
      - $ref: "../swagger.yaml#/parameters/per_page"
14
      - $ref: "../swagger.yaml#/parameters/q_param"
15
    produces:
16
      - application/json
17
    responses:
18
      "200":
19
        description: A biblio
20
      "401":
21
        description: Authentication required
22
        schema:
23
          $ref: "../swagger.yaml#/definitions/error"
24
      "403":
25
        description: Access forbidden
26
        schema:
27
          $ref: "../swagger.yaml#/definitions/error"
28
      "500":
29
        description: |
30
          Internal server error. Possible `error_code` attribute values:
31
32
          * `internal_server_error`
33
        schema:
34
          $ref: "../swagger.yaml#/definitions/error"
35
      "503":
36
        description: Under maintenance
37
        schema:
38
          $ref: "../swagger.yaml#/definitions/error"
39
    x-koha-authorization:
40
      permissions:
41
        catalogue: "1"
2
"/biblios/{biblio_id}":
42
"/biblios/{biblio_id}":
3
  get:
43
  get:
4
    x-mojo-to: Biblios#get
44
    x-mojo-to: Biblios#get
(-)a/api/v1/swagger/swagger.yaml (+2 lines)
Lines 93-98 paths: Link Here
93
    $ref: "./paths/advancededitormacros.yaml#/~1advanced_editor~1macros~1{advancededitormacro_id}"
93
    $ref: "./paths/advancededitormacros.yaml#/~1advanced_editor~1macros~1{advancededitormacro_id}"
94
  "/article_requests/{article_request_id}":
94
  "/article_requests/{article_request_id}":
95
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
95
    $ref: "./paths/article_requests.yaml#/~1article_requests~1{article_request_id}"
96
  "/biblios":
97
    $ref: "./paths/biblios.yaml#/~1biblios"
96
  "/biblios/{biblio_id}":
98
  "/biblios/{biblio_id}":
97
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
99
    $ref: "./paths/biblios.yaml#/~1biblios~1{biblio_id}"
98
  "/biblios/{biblio_id}/checkouts":
100
  "/biblios/{biblio_id}/checkouts":
(-)a/t/db_dependent/api/v1/biblios/list.t (+89 lines)
Line 0 Link Here
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use utf8;
21
use Encode;
22
23
use Test::More tests => 1;
24
use Test::MockModule;
25
use Test::Mojo;
26
use Test::Warn;
27
use JSON;
28
29
use t::lib::Mocks;
30
use t::lib::TestBuilder;
31
32
use C4::Auth;
33
34
use Koha::Biblios;
35
use Koha::Database;
36
37
my $schema  = Koha::Database->new->schema;
38
my $builder = t::lib::TestBuilder->new;
39
40
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
41
42
my $t = Test::Mojo->new('Koha::REST::V1');
43
44
subtest 'get() tests' => sub {
45
    plan tests => 13;
46
47
    $schema->storage->txn_begin;
48
    $schema->resultset('Biblio')->delete();
49
50
    my $patron = $builder->build_object(
51
        {
52
            class => 'Koha::Patrons',
53
            value => { flags => 0 }
54
        }
55
    );
56
    my $password = 'thePassword123';
57
    $patron->set_password( { password => $password, skip_validation => 1 } );
58
    $patron->discard_changes;
59
    my $userid = $patron->userid;
60
61
    my $biblio = $builder->build_sample_biblio({
62
        title  => 'The unbearable lightness of being',
63
        author => 'Milan Kundera',
64
        isbn => '0-06-093213-9',
65
    });
66
    $t->get_ok("//$userid:$password@/api/v1/biblios")
67
      ->status_is(403);
68
69
    $patron->flags(4)->store;
70
71
    $t->get_ok("//$userid:$password@/api/v1/biblios")
72
      ->status_is(200)
73
      ->json_is( '/0/title', 'The unbearable lightness of being' )
74
      ->json_is( '/0/author', 'Milan Kundera' )
75
      ->json_is( '/0/isbn', '0-06-093213-9' );
76
77
    # Test the ability to filter using biblioitems columns
78
    my $api_filter = encode_json({'isbn' => '123'});
79
    $t->get_ok("//$userid:$password@/api/v1/biblios?q=$api_filter")
80
      ->status_is(200)
81
      ->json_hasnt('/0');
82
83
    $api_filter = encode_json({'isbn' => '0-06-093213-9'});
84
    $t->get_ok("//$userid:$password@/api/v1/biblios?q=$api_filter")
85
      ->status_is(200)
86
      ->json_is('/0/isbn', '0-06-093213-9');
87
88
    $schema->storage->txn_rollback;
89
};
(-)a/t/lib/TestBuilder.pm (-1 / +7 lines)
Lines 166-171 sub build_sample_biblio { Link Here
166
        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
166
        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
167
    );
167
    );
168
168
169
    if ($args->{isbn}) {
170
        ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( '010', 'a' ) : ( '020', 'a' );
171
        $record->append_fields(
172
            MARC::Field->new( $tag, ' ', ' ', $subfield => $args->{isbn} ),
173
        );
174
    }
175
169
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 995, 'r' ) : ( 942, 'c' );
176
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 995, 'r' ) : ( 942, 'c' );
170
    $record->append_fields(
177
    $record->append_fields(
171
        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
178
        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
172
- 

Return to bug 30790