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

(-)a/Koha/REST/V1/Biblio.pm (+46 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 = $biblio->items();
39
40
    $biblio = $biblio->unblessed;
41
    $biblio->{items} = $items->unblessed;
42
43
    return $c->$cb($biblio, 200);
44
}
45
46
1;
(-)a/api/v1/definitions/biblio.json (+59 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "biblionumber": {
5
      "type": "string",
6
      "description": "unique identifier assigned to each bibliographic record"
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
        "$ref": "item.json"
56
      }
57
    }
58
  }
59
}
(-)a/api/v1/definitions/biblioitems.json (+56 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "biblionumber": {
5
      "type": "string",
6
      "description": "unique identifier assigned to each bibliographic record"
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": ["boolean", "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
      "$ref": "biblioitems.json"
54
    }
55
  }
56
}
(-)a/api/v1/definitions/index.json (+2 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
    "item": { "$ref": "item.json" },
6
    "biblio": { "$ref": "biblio.json" },
5
    "error": { "$ref": "error.json" }
7
    "error": { "$ref": "error.json" }
6
}
8
}
(-)a/api/v1/definitions/item.json (+177 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "itemnumber": {
5
      "type": "string",
6
      "description": "internally assigned item identifier"
7
    },
8
    "biblionumber": {
9
      "type": "string",
10
      "description": "internally assigned biblio identifier"
11
    },
12
    "biblioitemnumber": {
13
      "type": "string",
14
      "description": "internally assigned biblio item identifier"
15
    },
16
    "barcode": {
17
      "type": ["string", "null"],
18
      "description": "item barcode"
19
    },
20
    "dateaccessioned": {
21
      "type": ["string", "null"],
22
      "description": "date the item was acquired or added to Koha"
23
    },
24
    "booksellerid": {
25
      "type": ["string", "null"],
26
      "description": "where the item was purchased"
27
    },
28
    "homebranch": {
29
      "type": ["string", "null"],
30
      "description": "library that owns this item"
31
    },
32
    "price": {
33
      "type": ["string", "null"],
34
      "description": "purchase price"
35
    },
36
    "replacementprice": {
37
      "type": ["string", "null"],
38
      "description": "cost the library charges to replace the item if it has been marked lost"
39
    },
40
    "replacementpricedate": {
41
      "type": ["string", "null"],
42
      "description": "the date the price is effective from"
43
    },
44
    "datelastborrowed": {
45
      "type": ["string", "null"],
46
      "description": "the date the item was last checked out/issued"
47
    },
48
    "datelastseen": {
49
      "type": ["string", "null"],
50
      "description": "the date the item was last see (usually the last time the barcode was scanned or inventory was done)"
51
    },
52
    "stack": {
53
      "type": ["string", "null"],
54
      "description": "?"
55
    },
56
    "notforloan": {
57
      "type": "string",
58
      "description": "authorized value defining why this item is not for loan"
59
    },
60
    "damaged": {
61
      "type": "string",
62
      "description": "authorized value defining this item as damaged"
63
    },
64
    "itemlost": {
65
      "type": "string",
66
      "description": "authorized value defining this item as lost"
67
    },
68
    "itemlost_on": {
69
      "type": ["string", "null"],
70
      "description": "the date and time an item was last marked as lost, NULL if not lost"
71
    },
72
    "withdrawn": {
73
      "type": "string",
74
      "description": "authorized value defining this item as withdrawn"
75
    },
76
    "withdrawn_on": {
77
      "type": ["string", "null"],
78
      "description": "the date and time an item was last marked as withdrawn, NULL if not withdrawn"
79
    },
80
    "itemcallnumber": {
81
      "type": ["string", "null"],
82
      "description": "call number for this item"
83
    },
84
    "coded_location_qualifier": {
85
      "type": ["string", "null"],
86
      "description": "coded location qualifier"
87
    },
88
    "issues": {
89
      "type": ["string", "null"],
90
      "description": "number of times this item has been checked out/issued"
91
    },
92
    "renewals": {
93
      "type": ["string", "null"],
94
      "description": "number of times this item has been renewed"
95
    },
96
    "reserves": {
97
      "type": ["string", "null"],
98
      "description": "number of times this item has been placed on hold/reserved"
99
    },
100
    "restricted": {
101
      "type": ["string", "null"],
102
      "description": "authorized value defining use restrictions for this item"
103
    },
104
    "itemnotes": {
105
      "type": ["string", "null"],
106
      "description": "public notes on this item"
107
    },
108
    "itemnotes_nonpublic": {
109
      "type": ["string", "null"],
110
      "description": "non-public notes on this item"
111
    },
112
    "holdingbranch": {
113
      "type": ["string", "null"],
114
      "description": "library that is currently in possession item"
115
    },
116
    "paidfor": {
117
      "type": ["string", "null"],
118
      "description": "?"
119
    },
120
    "timestamp": {
121
      "type": "string",
122
      "description": "date and time this item was last altered"
123
    },
124
    "location": {
125
      "type": ["string", "null"],
126
      "description": "authorized value for the shelving location for this item"
127
    },
128
    "permanent_location": {
129
      "type": ["string", "null"],
130
      "description": "linked to the CART and PROC temporary locations feature, stores the permanent shelving location"
131
    },
132
    "onloan": {
133
      "type": ["string", "null"],
134
      "description": "defines if item is checked out (NULL for not checked out, and checkout date for checked out)"
135
    },
136
    "cn_source": {
137
      "type": ["string", "null"],
138
      "description": "classification source used on this item"
139
    },
140
    "cn_sort": {
141
      "type": ["string", "null"],
142
      "description": "?"
143
    },
144
    "ccode": {
145
      "type": ["string", "null"],
146
      "description": "authorized value for the collection code associated with this item"
147
    },
148
    "materials": {
149
      "type": ["string", "null"],
150
      "description": "materials specified"
151
    },
152
    "uri": {
153
      "type": ["string", "null"],
154
      "description": "URL for the item"
155
    },
156
    "itype": {
157
      "type": ["string", "null"],
158
      "description": "itemtype defining the type for this item"
159
    },
160
    "more_subfields_xml": {
161
      "type": ["string", "null"],
162
      "description": "additional 952 subfields in XML format"
163
    },
164
    "enumchron": {
165
      "type": ["string", "null"],
166
      "description": "serial enumeration/chronology for the item"
167
    },
168
    "copynumber": {
169
      "type": ["string", "null"],
170
      "description": "copy number"
171
    },
172
    "stocknumber": {
173
      "type": ["string", "null"],
174
      "description": "inventory number"
175
    }
176
  }
177
}
(-)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