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

(-)a/Koha/REST/V1/Biblio.pm (+48 lines)
Line 0 Link Here
1
package Koha::REST::V1::Biblio;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
use Mojo::JSON;
22
23
use C4::Auth qw( haspermission );
24
25
use Koha::Biblios;
26
use Koha::Items;
27
28
sub get {
29
    my ($c, $args, $cb) = @_;
30
31
    my $biblionumber = $c->param('biblionumber');
32
    my $biblio = Koha::Biblios->find($biblionumber);
33
34
    unless ($biblio) {
35
        return $c->$cb({error => "Biblio not found"}, 404);
36
    }
37
38
    my $items ||= Koha::Items->search( { biblionumber => $biblionumber }, {
39
	       columns => [qw/itemnumber/],
40
    });
41
42
    $biblio = $biblio->unblessed;
43
    $biblio->{items} = $items->unblessed;
44
45
    return $c->$cb($biblio, 200);
46
}
47
48
1;
(-)a/api/v1/definitions/biblio.json (+65 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "biblionumber": {
5
      "type": "string",
6
      "description": "internal bibliographic record identifier"
7
    },
8
    "frameworkcode": {
9
      "type": "string",
10
      "description": "foreign key from the biblio_framework table to identify which framework was used in cataloging this record"
11
    },
12
    "author": {
13
      "type": ["string", "null"],
14
      "description": "statement of responsibility from MARC record (100$a in MARC21)"
15
    },
16
    "title": {
17
      "type": ["string", "null"],
18
      "description": "title (without the subtitle) from the MARC record (245$a in MARC21)"
19
    },
20
    "untitle": {
21
      "type": ["string", "null"],
22
      "description": "uniform title (without the subtitle) from the MARC record (240$a in MARC21)"
23
    },
24
    "notes": {
25
      "type": ["string", "null"],
26
      "description": "values from the general notes field in the MARC record (500$a in MARC21) split by bar (|)"
27
    },
28
    "serial": {
29
      "type": ["string", "null"],
30
      "description": "Boolean indicating whether biblio is for a serial"
31
    },
32
    "seriestitle": {
33
      "type": ["string", "null"],
34
      "description": "Title for describing the series"
35
    },
36
    "copyrightdate": {
37
      "type": ["string", "null"],
38
      "description": "publication or copyright date from the MARC record"
39
    },
40
    "timestamp": {
41
      "type": "string",
42
      "description": "date and time this record was last touched"
43
    },
44
    "datecreated": {
45
      "type": "string",
46
      "description": "the date this record was added to Koha"
47
    },
48
    "abstract": {
49
      "type": ["string", "null"],
50
      "description": "summary from the MARC record (520$a in MARC21)"
51
    },
52
    "items": {
53
      "type": "array",
54
      "items": {
55
        "type": "object",
56
        "properties": {
57
          "itemnumber": {
58
            "type": "string",
59
            "description": "internal item identifier"
60
          }
61
        }
62
      }
63
    }
64
  }
65
}
(-)a/api/v1/definitions/index.json (+1 lines)
Lines 2-6 Link Here
2
    "patron": { "$ref": "patron.json" },
2
    "patron": { "$ref": "patron.json" },
3
    "holds": { "$ref": "holds.json" },
3
    "holds": { "$ref": "holds.json" },
4
    "hold": { "$ref": "hold.json" },
4
    "hold": { "$ref": "hold.json" },
5
    "biblio": { "$ref": "biblio.json" },
5
    "error": { "$ref": "error.json" }
6
    "error": { "$ref": "error.json" }
6
}
7
}
(-)a/api/v1/swagger.json (+32 lines)
Lines 332-337 Link Here
332
          }
332
          }
333
        }
333
        }
334
      }
334
      }
335
    },
336
    "/biblios/{biblionumber}": {
337
      "get": {
338
        "operationId": "getBiblio",
339
        "tags": ["biblios"],
340
        "parameters": [
341
          { "$ref": "#/parameters/biblionumberPathParam" }
342
        ],
343
        "consumes": ["application/json"],
344
        "produces": ["application/json"],
345
        "responses": {
346
          "200": {
347
            "description": "An biblio",
348
            "schema": { "$ref": "#/definitions/biblio" }
349
          },
350
          "400": {
351
            "description": "Missing or wrong parameters",
352
            "schema": { "$ref": "#/definitions/error" }
353
          },
354
          "404": {
355
            "description": "Biblio not found",
356
            "schema": { "$ref": "#/definitions/error" }
357
          }
358
        }
359
      }
335
    }
360
    }
336
  },
361
  },
337
  "definitions": {
362
  "definitions": {
Lines 351-356 Link Here
351
      "description": "Internal hold identifier",
376
      "description": "Internal hold identifier",
352
      "required": true,
377
      "required": true,
353
      "type": "integer"
378
      "type": "integer"
379
    },
380
    "biblionumberPathParam": {
381
        "name": "biblionumber",
382
        "in": "path",
383
        "description": "Internal biblio identifier",
384
        "required": true,
385
        "type": "integer"
354
    }
386
    }
355
  }
387
  }
356
}
388
}
(-)a/t/db_dependent/api/v1/biblios.t (-1 / +116 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# Copyright 2016 Koha-Suomi
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Test::More tests => 7;
23
use Test::Mojo;
24
use t::lib::TestBuilder;
25
26
use C4::Auth;
27
use C4::Biblio;
28
use C4::Context;
29
use C4::Items;
30
31
use Koha::Database;
32
use Koha::Patron;
33
use Koha::Items;
34
35
my $builder = t::lib::TestBuilder->new();
36
37
my $dbh = C4::Context->dbh;
38
$dbh->{AutoCommit} = 0;
39
$dbh->{RaiseError} = 1;
40
41
$ENV{REMOTE_ADDR} = '127.0.0.1';
42
my $t = Test::Mojo->new('Koha::REST::V1');
43
44
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
45
my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode };
46
my $borrower = $builder->build({
47
    source => 'Borrower',
48
    value => {
49
        branchcode   => $branchcode,
50
        categorycode => $categorycode,
51
        flags => 16,
52
    }
53
});
54
55
my $librarian = $builder->build({
56
    source => "Borrower",
57
    value => {
58
        categorycode => $categorycode,
59
        branchcode => $branchcode,
60
        flags => 4,
61
    },
62
});
63
64
my ($session) = create_session($borrower);
65
66
my $biblio = $builder->build({
67
    source => 'Biblio'
68
});
69
my $biblionumber = $biblio->{biblionumber};
70
my $item1 = $builder->build({
71
    source => 'Item',
72
    value => {
73
        biblionumber => $biblionumber,
74
    }
75
});
76
my $item2 = $builder->build({
77
    source => 'Item',
78
    value => {
79
        biblionumber => $biblionumber,
80
    }
81
});
82
my $item1number = $item1->{itemnumber};
83
my $item2number = $item2->{itemnumber};
84
85
my $nonExistentBiblionumber = -14362719;
86
my $tx = $t->ua->build_tx(GET => "/api/v1/biblios/$nonExistentBiblionumber");
87
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
88
$t->request_ok($tx)
89
  ->status_is(404);
90
91
$tx = $t->ua->build_tx(GET => "/api/v1/biblios/$biblionumber");
92
$tx->req->cookies({name => 'CGISESSID', value => $session->id});
93
$t->request_ok($tx)
94
  ->status_is(200)
95
  ->json_is('/items/0/itemnumber' => $item1number)
96
  ->json_is('/items/1/itemnumber' => $item2number)
97
  ->json_is('/biblionumber' => $biblionumber);
98
99
$dbh->rollback;
100
101
sub create_session {
102
    my (@borrowers) = @_;
103
104
    my @sessions;
105
    foreach $borrower (@borrowers) {
106
        my $session = C4::Auth::get_session('');
107
        $session->param('number', $borrower->{borrowernumber});
108
        $session->param('id', $borrower->{userid});
109
        $session->param('ip', '127.0.0.1');
110
        $session->param('lasttime', time());
111
        $session->flush;
112
        push @sessions, $session;
113
    }
114
115
    return @sessions;
116
}

Return to bug 17007