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 $branchcode = $c->param('branchcode');
34
    my $library = Koha::Libraries->find({branchcode => $branchcode});
35
    unless ($library) {
36
        return $c->$cb({error => "Library with branchcode \"$branchcode\" not found"}, 404);
37
    }
38
39
    return $c->$cb($library->unblessed, 200);
40
}
41
42
1;
(-)a/api/v1/swagger/definitions.json (+6 lines)
Lines 8-13 Link Here
8
  "hold": {
8
  "hold": {
9
    "$ref": "definitions/hold.json"
9
    "$ref": "definitions/hold.json"
10
  },
10
  },
11
  "libraries": {
12
    "$ref": "definitions/libraries.json"
13
  },
14
  "library": {
15
    "$ref": "definitions/library.json"
16
  },
11
  "error": {
17
  "error": {
12
    "$ref": "definitions/error.json"
18
    "$ref": "definitions/error.json"
13
  }
19
  }
(-)a/api/v1/swagger/definitions/libraries.json (+6 lines)
Line 0 Link Here
1
{
2
  "type": "array",
3
  "items": {
4
    "$ref": "library.json"
5
  }
6
}
(-)a/api/v1/swagger/definitions/library.json (+76 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "branchcode": {
5
      "$ref": "../x-primitives.json#/branchcode"
6
    },
7
    "branchname": {
8
      "type": "string",
9
      "description": "Printable name of library"
10
    },
11
    "branchaddress1": {
12
      "type": [ "string", "null" ],
13
      "description": "the first address line of the library"
14
    },
15
    "branchaddress2": {
16
      "type": [ "string", "null" ],
17
      "description": "the second address line of the library"
18
    },
19
    "branchaddress3": {
20
      "type": [ "string", "null" ],
21
      "description": "the third address line of the library"
22
    },
23
    "branchzip": {
24
      "type": [ "string", "null" ],
25
      "description": "the zip or postal code of the library"
26
    },
27
    "branchcity": {
28
      "type": [ "string", "null" ],
29
      "description": "the city or province of the library"
30
    },
31
    "branchstate": {
32
      "type": [ "string", "null" ],
33
      "description": "the reqional state of the library"
34
    },
35
    "branchcountry": {
36
      "type": [ "string", "null" ],
37
      "description": "the county of the library"
38
    },
39
    "branchphone": {
40
      "type": [ "string", "null" ],
41
      "description": "the primary phone of the library"
42
    },
43
    "branchfax": {
44
      "type": [ "string", "null" ],
45
      "description": "the fax number of the library"
46
    },
47
    "branchemail": {
48
      "type": [ "string", "null" ],
49
      "description": "the primary email address of the library"
50
    },
51
    "branchreplyto": {
52
      "type": [ "string", "null" ],
53
      "description": "the email to be used as a Reply-To"
54
    },
55
    "branchreturnpath": {
56
      "type": [ "string", "null" ],
57
      "description": "the email to be used as Return-Path"
58
    },
59
    "branchurl": {
60
      "type": [ "string", "null" ],
61
      "description": "the URL for your library or branch's website"
62
    },
63
    "branchip": {
64
      "type": [ "string", "null" ],
65
      "description": "the IP address for your library or branch"
66
    },
67
    "branchnotes": {
68
      "type": [ "string", "null" ],
69
      "description": "notes related to your library or branch"
70
    },
71
    "opac_info": {
72
      "type": [ "string", "null" ],
73
      "description": "HTML that displays in OPAC"
74
    }
75
  }
76
}
(-)a/api/v1/swagger/parameters.json (+3 lines)
Lines 7-11 Link Here
7
  },
7
  },
8
  "holdIdPathParam": {
8
  "holdIdPathParam": {
9
    "$ref": "parameters/hold.json#/holdIdPathParam"
9
    "$ref": "parameters/hold.json#/holdIdPathParam"
10
  },
11
  "branchcodePathParam": {
12
    "$ref": "parameters/library.json#/branchcodePathParam"
10
  }
13
  }
11
}
14
}
(-)a/api/v1/swagger/parameters/library.json (+9 lines)
Line 0 Link Here
1
{
2
  "branchcodePathParam": {
3
    "name": "branchcode",
4
    "in": "path",
5
    "description": "Branch identifier code",
6
    "required": true,
7
    "type": "string"
8
  }
9
}
(-)a/api/v1/swagger/paths.json (+6 lines)
Lines 10-14 Link Here
10
  },
10
  },
11
  "/patrons/{borrowernumber}": {
11
  "/patrons/{borrowernumber}": {
12
    "$ref": "paths/patrons.json#/~1patrons~1{borrowernumber}"
12
    "$ref": "paths/patrons.json#/~1patrons~1{borrowernumber}"
13
  },
14
  "/libraries": {
15
    "$ref": "paths/libraries.json#/~1libraries"
16
  },
17
  "/libraries/{branchcode}": {
18
    "$ref": "paths/libraries.json#/~1libraries~1{branchcode}"
13
  }
19
  }
14
}
20
}
(-)a/api/v1/swagger/paths/libraries.json (+47 lines)
Line 0 Link Here
1
{
2
  "/libraries": {
3
    "get": {
4
      "operationId": "listLibrary",
5
      "tags": ["libraries"],
6
      "produces": [
7
        "application/json"
8
      ],
9
      "responses": {
10
        "200": {
11
          "description": "A list of libraries",
12
          "schema": {
13
            "$ref": "../definitions.json#/libraries"
14
          }
15
        }
16
      }
17
    }
18
  },
19
  "/libraries/{branchcode}": {
20
    "get": {
21
      "operationId": "getLibrary",
22
      "tags": ["libraries"],
23
      "parameters": [
24
        {
25
          "$ref": "../parameters.json#/branchcodePathParam"
26
        }
27
      ],
28
      "produces": [
29
        "application/json"
30
      ],
31
      "responses": {
32
        "200": {
33
          "description": "A library",
34
          "schema": {
35
            "$ref": "../definitions.json#/library"
36
          }
37
        },
38
        "404": {
39
          "description": "Library not found",
40
          "schema": {
41
            "$ref": "../definitions.json#/error"
42
          }
43
        }
44
      }
45
    }
46
  }
47
}
(-)a/t/db_dependent/api/v1/libraries.t (-1 / +63 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;

Return to bug 16497