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

(-)a/Koha/REST/V1/Library.pm (+42 lines)
Line 0 Link Here
1
package Koha::REST::V1::Library;
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 Koha::Libraries;
22
23
sub list {
24
    my ($c, $args, $cb) = @_;
25
26
    my $libraries = Koha::Libraries->search;
27
    return $c->$cb($libraries->unblessed, 200);
28
}
29
30
sub get {
31
    my ($c, $args, $cb) = @_;
32
33
    my $brancocode = $c->param('branchcode');
34
    my $library = Koha::Libraries->find({branchcode => $brancocode});
35
    unless ($library) {
36
        return $c->$cb({error => "Library with branchcode \"$brancocode\" not found"}, 404);
37
    }
38
39
    return $c->$cb($library->unblessed, 200);
40
}
41
42
1;
(-)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
    "libraries": { "$ref": "libraries.json" },
6
    "library": { "$ref": "library.json" },
5
    "error": { "$ref": "error.json" }
7
    "error": { "$ref": "error.json" }
6
}
8
}
(-)a/api/v1/definitions/libraries.json (+4 lines)
Line 0 Link Here
1
{
2
    "type": "array",
3
    "items": { "$ref": "library.json" }
4
}
(-)a/api/v1/definitions/library.json (+77 lines)
Line 0 Link Here
1
{
2
    "type": "object",
3
    "properties": {
4
        "branchcode": {
5
            "type": "string",
6
            "description": "Internal library identifier"
7
        },
8
        "branchname": {
9
            "type": "string",
10
            "description": "Printable name of library"
11
        },
12
        "branchaddress1": {
13
            "type": ["string", "null"],
14
            "description": "the first address line of the library"
15
        },
16
        "branchaddress2": {
17
            "type": ["string", "null"],
18
            "description": "the second address line of the library"
19
        },
20
        "branchaddress3": {
21
            "type": ["string", "null"],
22
            "description": "the third address line of the library"
23
        },
24
        "branchzip": {
25
            "type": ["string", "null"],
26
            "description": "the zip or postal code of the library"
27
        },
28
        "branchcity": {
29
            "type": ["string", "null"],
30
            "description": "the city or province of the library"
31
        },
32
        "branchstate": {
33
            "type": ["string", "null"],
34
            "description": "the reqional state of the library"
35
        },
36
        "branchcountry": {
37
            "type": ["string", "null"],
38
            "description": "the county of the library"
39
        },
40
        "branchphone": {
41
            "type": ["string", "null"],
42
            "description": "the primary phone of the library"
43
        },
44
        "branchfax": {
45
            "type": ["string", "null"],
46
            "description": "the fax number of the library"
47
        },
48
        "branchemail": {
49
            "type": ["string", "null"],
50
            "description": "the primary email address of the library"
51
        },
52
        "branchreplyto": {
53
            "type": ["string", "null"],
54
            "description": "the email to be used as a Reply-To"
55
        },
56
        "branchreturnpath": {
57
            "type": ["string", "null"],
58
            "description": "the email to be used as Return-Path"
59
        },
60
        "branchurl": {
61
            "type": ["string", "null"],
62
            "description": "the URL for your library or branch's website"
63
        },
64
        "branchip": {
65
            "type": ["string", "null"],
66
            "description": "the IP address for your library or branch"
67
        },
68
        "branchnotes": {
69
            "type": ["string", "null"],
70
            "description": "notes related to your library or branch"
71
        },
72
        "opac_info": {
73
            "type": ["string", "null"],
74
            "description": "HTML that displays in OPAC"
75
        }
76
    }
77
}
(-)a/api/v1/swagger.json (+50 lines)
Lines 231-236 Link Here
231
          }
231
          }
232
        }
232
        }
233
      }
233
      }
234
    },
235
    "/libraries": {
236
      "get": {
237
        "operationId": "listLibrary",
238
        "tags": ["libraries"],
239
        "produces": [
240
          "application/json"
241
        ],
242
        "responses": {
243
          "200": {
244
            "description": "A list of libraries",
245
            "schema": {
246
              "$ref": "#/definitions/libraries"
247
            }
248
          }
249
        }
250
      }
251
    },
252
    "/libraries/{branchcode}": {
253
      "get": {
254
        "operationId": "getLibrary",
255
        "tags": ["libraries"],
256
        "parameters": [
257
          { "$ref": "#/parameters/branchcodePathParam" }
258
        ],
259
        "produces": [
260
          "application/json"
261
        ],
262
        "responses": {
263
          "200": {
264
            "description": "A library",
265
            "schema": {
266
              "$ref": "#/definitions/library"
267
            }
268
          },
269
          "404": {
270
            "description": "Library not found",
271
            "schema": {
272
              "$ref": "#/definitions/error"
273
            }
274
          }
275
        }
276
      }
234
    }
277
    }
235
  },
278
  },
236
  "definitions": {
279
  "definitions": {
Lines 250-255 Link Here
250
      "description": "Internal hold identifier",
293
      "description": "Internal hold identifier",
251
      "required": true,
294
      "required": true,
252
      "type": "integer"
295
      "type": "integer"
296
    },
297
    "branchcodePathParam": {
298
      "name": "branchcode",
299
      "in": "path",
300
      "description": "Internal library identifier",
301
      "required": true,
302
      "type": "string"
253
    }
303
    }
254
  }
304
  }
255
}
305
}
(-)a/t/db_dependent/api/v1/libraries.t (-1 / +64 lines)
Line 0 Link Here
0
- 
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 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 t::lib::TestBuilder;
21
22
use Test::More tests => 11;
23
use Test::Mojo;
24
25
use C4::Auth;
26
use C4::Context;
27
use Koha::Database;
28
29
BEGIN {
30
    use_ok('Koha::Object');
31
    use_ok('Koha::Libraries');
32
}
33
34
my $schema  = Koha::Database->schema;
35
my $dbh     = C4::Context->dbh;
36
my $builder = t::lib::TestBuilder->new;
37
38
$ENV{REMOTE_ADDR} = '127.0.0.1';
39
my $t = Test::Mojo->new('Koha::REST::V1');
40
41
$schema->storage->txn_begin;
42
43
my $branch = $builder->build({ source => 'Branch' });
44
45
my $tx = $t->ua->build_tx(GET => '/api/v1/libraries');
46
#$tx->req->cookies({name => 'CGISESSID', value => $session->id});
47
$tx->req->env({REMOTE_ADDR => '127.0.0.1'});
48
$t->request_ok($tx)
49
  ->status_is(200);
50
51
$tx = $t->ua->build_tx(GET => "/api/v1/libraries/" . $branch->{ branchcode });
52
#$tx->req->cookies({name => 'CGISESSID', value => $session->id});
53
$t->request_ok($tx)
54
  ->status_is(200)
55
  ->json_is('/branchcode' => $branch->{ branchcode })
56
  ->json_is('/branchname' => $branch->{ branchname });
57
58
$tx = $t->ua->build_tx(GET => "/api/v1/libraries/" . "nonexistent");
59
$t->request_ok($tx)
60
  ->status_is(404)
61
  ->json_is('/error' => "Library with branchcode \"nonexistent\" not found");
62
63
$schema->storage->txn_rollback;
64

Return to bug 16497