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

(-)a/Koha/REST/V1/Library.pm (-58 / +191 lines)
Lines 43-69 Controller function that handles listing Koha::Library objects Link Here
43
sub list {
43
sub list {
44
    my $c = shift->openapi->valid_input or return;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    my $libraries;
47
    my $filter;
48
    my $args = $c->req->params->to_hash;
49
50
    for my $filter_param ( keys %$args ) {
51
        $filter->{$filter_param} = { LIKE => $args->{$filter_param} . "%" };
52
    }
53
54
    return try {
46
    return try {
55
        my $libraries = Koha::Libraries->search($filter);
47
        my $libraries_set = Koha::Libraries->new;
48
        my $libraries     = $c->objects->search( $libraries_set, \&_to_model, \&_to_api );
56
        return $c->render( status => 200, openapi => $libraries );
49
        return $c->render( status => 200, openapi => $libraries );
57
    }
50
    }
58
    catch {
51
    catch {
59
        if ( $_->isa('DBIx::Class::Exception') ) {
52
        unless ( blessed $_ && $_->can('rethrow') ) {
60
            return $c->render( status  => 500,
53
            return $c->render(
61
                               openapi => { error => $_->{msg} } );
54
                status  => 500,
62
        }
55
                openapi => { error => "Something went wrong, check Koha logs for details." }
63
        else {
56
            );
64
            return $c->render( status => 500,
65
                openapi => { error => "Something went wrong, check the logs."} );
66
        }
57
        }
58
        return $c->render(
59
            status  => 500,
60
            openapi => { error => "$_" }
61
        );
67
    };
62
    };
68
}
63
}
69
64
Lines 76-89 Controller function that handles retrieving a single Koha::Library Link Here
76
sub get {
71
sub get {
77
    my $c = shift->openapi->valid_input or return;
72
    my $c = shift->openapi->valid_input or return;
78
73
79
    my $branchcode = $c->validation->param('branchcode');
74
    my $library_id = $c->validation->param('library_id');
80
    my $library = Koha::Libraries->find({ branchcode => $branchcode });
75
    my $library = Koha::Libraries->find( $library_id );
76
81
    unless ($library) {
77
    unless ($library) {
82
        return $c->render( status  => 404,
78
        return $c->render( status  => 404,
83
                           openapi => { error => "Library not found" } );
79
                           openapi => { error => "Library not found" } );
84
    }
80
    }
85
81
86
    return $c->render( status => 200, openapi => $library );
82
    return $c->render( status => 200, openapi => _to_api( $library->TO_JSON ) );
87
}
83
}
88
84
89
=head3 add
85
=head3 add
Lines 96-118 sub add { Link Here
96
    my $c = shift->openapi->valid_input or return;
92
    my $c = shift->openapi->valid_input or return;
97
93
98
    return try {
94
    return try {
99
        if (Koha::Libraries->find($c->req->json->{branchcode})) {
95
        my $library = Koha::Library->new( _to_model( $c->validation->param('body') ) );
100
            return $c->render( status => 400,
96
        $library->store;
101
                openapi => { error => 'Library already exists' } );
97
        $c->res->headers->location( $c->req->url->to_string . '/' . $library->branchcode );
102
        }
98
        return $c->render( status => 201, openapi => _to_api( $library->TO_JSON ) );
103
        my $library = Koha::Library->new($c->validation->param('body'))->store;
104
        my $branchcode = $library->branchcode;
105
        $c->res->headers->location($c->req->url->to_string.'/'.$branchcode);
106
        return $c->render( status => 201, openapi => $library);
107
    }
99
    }
108
    catch {
100
    catch {
109
        if ( $_->isa('DBIx::Class::Exception') ) {
101
        unless ( blessed $_ && $_->can('rethrow') ) {
110
            return $c->render( status  => 500,
102
            return $c->render(
111
                               openapi => { error => $_->{msg} } );
103
                status  => 500,
104
                openapi => { error => "Something went wrong, check Koha logs for details." }
105
            );
106
        }
107
        if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
108
            return $c->render(
109
                status  => 409,
110
                openapi => { error => $_->error, conflict => $_->duplicate_id }
111
            );
112
        }
112
        }
113
        else {
113
        else {
114
            return $c->render( status => 500,
114
            return $c->render(
115
                openapi => { error => "Something went wrong, check the logs."} );
115
                status  => 500,
116
                openapi => { error => "$_" }
117
            );
116
        }
118
        }
117
    };
119
    };
118
}
120
}
Lines 126-150 Controller function that handles updating a Koha::Library object Link Here
126
sub update {
128
sub update {
127
    my $c = shift->openapi->valid_input or return;
129
    my $c = shift->openapi->valid_input or return;
128
130
129
    my $library;
131
    my $library = Koha::Libraries->find( $c->validation->param('library_id') );
132
133
    if ( not defined $library ) {
134
        return $c->render(
135
            status  => 404,
136
            openapi => { error => "Library not found" }
137
        );
138
    }
139
130
    return try {
140
    return try {
131
        $library = Koha::Libraries->find($c->validation->param('branchcode'));
141
        my $params = $c->req->json;
132
        $library->set($c->validation->param('body'))->store;
142
        $library->set( _to_model($params) );
133
        return $c->render( status => 200, openapi => $library );
143
        $library->store();
144
        return $c->render( status => 200, openapi => _to_api($library->TO_JSON) );
134
    }
145
    }
135
    catch {
146
    catch {
136
        if ( not defined $library ) {
147
        unless ( blessed $_ && $_->can('rethrow') ) {
137
            return $c->render( status => 404,
148
            return $c->render(
138
                               openapi => { error => "Object not found" });
149
                status  => 500,
139
        }
150
                openapi => { error => "Something went wrong, check Koha logs for details." }
140
        elsif ( $_->isa('DBIx::Class::Exception') ) {
151
            );
141
            return $c->render( status  => 500,
142
                               openapi => { error => $_->{msg} } );
143
        }
144
        else {
145
            return $c->render( status => 500,
146
                openapi => { error => "Something went wrong, check the logs."} );
147
        }
152
        }
153
154
        return $c->render(
155
            status  => 500,
156
            openapi => { error => "$_" }
157
        );
148
    };
158
    };
149
}
159
}
150
160
Lines 155-181 Controller function that handles deleting a Koha::Library object Link Here
155
=cut
165
=cut
156
166
157
sub delete {
167
sub delete {
168
158
    my $c = shift->openapi->valid_input or return;
169
    my $c = shift->openapi->valid_input or return;
159
170
160
    my $library;
171
    my $library = Koha::Libraries->find( $c->validation->param( 'library_id' ) );
172
173
    if ( not defined $library ) {
174
        return $c->render( status => 404, openapi => { error => "Library not found" } );
175
    }
176
161
    return try {
177
    return try {
162
        $library = Koha::Libraries->find($c->validation->param('branchcode'));
163
        $library->delete;
178
        $library->delete;
164
        return $c->render( status => 204, openapi => '');
179
        return $c->render( status => 204, openapi => '');
165
    }
180
    }
166
    catch {
181
    catch {
167
        if ( not defined $library ) {
182
        unless ( blessed $_ && $_->can('rethrow') ) {
168
            return $c->render( status => 404, openapi => { error => "Object not found" } );
183
            return $c->render(
184
                status  => 500,
185
                openapi => { error => "Something went wrong, check Koha logs for details." }
186
            );
169
        }
187
        }
170
        elsif ( $_->isa('DBIx::Class::Exception') ) {
188
171
            return $c->render( status  => 500,
189
        return $c->render(
172
                               openapi => { error => $_->{msg} } );
190
            status  => 500,
191
            openapi => { error => "$_" }
192
        );
193
    };
194
}
195
196
=head3 _to_api
197
198
Helper function that maps a hashref of Koha::Library attributes into REST api
199
attribute names.
200
201
=cut
202
203
sub _to_api {
204
    my $library = shift;
205
206
    # Rename attributes
207
    foreach my $column ( keys %{ $Koha::REST::V1::Library::to_api_mapping } ) {
208
        my $mapped_column = $Koha::REST::V1::Library::to_api_mapping->{$column};
209
        if (    exists $library->{ $column }
210
             && defined $mapped_column )
211
        {
212
            # key /= undef
213
            $library->{ $mapped_column } = delete $library->{ $column };
173
        }
214
        }
174
        else {
215
        elsif (    exists $library->{ $column }
175
            return $c->render( status => 500,
216
                && !defined $mapped_column )
176
                openapi => { error => "Something went wrong, check the logs."} );
217
        {
218
            # key == undef => to be deleted
219
            delete $library->{ $column };
177
        }
220
        }
178
    };
221
    }
222
223
    return $library;
224
}
225
226
=head3 _to_model
227
228
Helper function that maps REST api objects into Koha::Library
229
attribute names.
230
231
=cut
232
233
sub _to_model {
234
    my $library = shift;
235
236
    foreach my $attribute ( keys %{ $Koha::REST::V1::Library::to_model_mapping } ) {
237
        my $mapped_attribute = $Koha::REST::V1::Library::to_model_mapping->{$attribute};
238
        if (    exists $library->{ $attribute }
239
             && defined $mapped_attribute )
240
        {
241
            # key /= undef
242
            $library->{ $mapped_attribute } = delete $library->{ $attribute };
243
        }
244
        elsif (    exists $library->{ $attribute }
245
                && !defined $mapped_attribute )
246
        {
247
            # key == undef => to be deleted
248
            delete $library->{ $attribute };
249
        }
250
    }
251
252
    if ( exists $library->{pickup_location} ) {
253
        $library->{pickup_location} = ( $library->{pickup_location} ) ? 1 : 0;
254
    }
255
256
    return $library;
179
}
257
}
180
258
259
260
=head2 Global variables
261
262
=head3 $to_api_mapping
263
264
=cut
265
266
our $to_api_mapping = {
267
    branchcode       => 'library_id',
268
    branchname       => 'name',
269
    branchaddress1   => 'address1',
270
    branchaddress2   => 'address2',
271
    branchaddress3   => 'address3',
272
    branchzip        => 'postal_code',
273
    branchcity       => 'city',
274
    branchstate      => 'state',
275
    branchcountry    => 'country',
276
    branchphone      => 'phone',
277
    branchfax        => 'fax',
278
    branchemail      => 'email',
279
    branchreplyto    => 'reply_to_email',
280
    branchreturnpath => 'return_path_email',
281
    branchurl        => 'url',
282
    issuing          => undef,
283
    branchip         => 'ip',
284
    branchprinter    => undef,
285
    branchnotes      => 'notes',
286
    marcorgcode      => 'marc_org_code',
287
};
288
289
=head3 $to_model_mapping
290
291
=cut
292
293
our $to_model_mapping = {
294
    library_id        => 'branchcode',
295
    name              => 'branchname',
296
    address1          => 'branchaddress1',
297
    address2          => 'branchaddress2',
298
    address3          => 'branchaddress3',
299
    postal_code       => 'branchzip',
300
    city              => 'branchcity',
301
    state             => 'branchstate',
302
    country           => 'branchcountry',
303
    phone             => 'branchphone',
304
    fax               => 'branchfax',
305
    email             => 'branchemail',
306
    reply_to_email    => 'branchreplyto',
307
    return_path_email => 'branchreturnpath',
308
    url               => 'branchurl',
309
    ip                => 'branchip',
310
    notes             => 'branchnotes',
311
    marc_org_code     => 'marcorgcode',
312
};
313
181
1;
314
1;
(-)a/api/v1/swagger/definitions/library.json (-29 / +25 lines)
Lines 1-78 Link Here
1
{
1
{
2
  "type": "object",
2
  "type": "object",
3
  "properties": {
3
  "properties": {
4
    "branchcode": {
4
    "library_id": {
5
      "$ref": "../x-primitives.json#/branchcode"
5
      "$ref": "../x-primitives.json#/library_id"
6
    },
6
    },
7
    "branchname": {
7
    "name": {
8
      "type": "string",
8
      "type": "string",
9
      "description": "Printable name of library"
9
      "description": "Printable name of library"
10
    },
10
    },
11
    "branchaddress1": {
11
    "address1": {
12
      "type": ["string", "null"],
12
      "type": ["string", "null"],
13
      "description": "the first address line of the library"
13
      "description": "the first address line of the library"
14
    },
14
    },
15
    "branchaddress2": {
15
    "address2": {
16
      "type": ["string", "null"],
16
      "type": ["string", "null"],
17
      "description": "the second address line of the library"
17
      "description": "the second address line of the library"
18
    },
18
    },
19
    "branchaddress3": {
19
    "address3": {
20
      "type": ["string", "null"],
20
      "type": ["string", "null"],
21
      "description": "the third address line of the library"
21
      "description": "the third address line of the library"
22
    },
22
    },
23
    "branchzip": {
23
    "postal_code": {
24
      "type": ["string", "null"],
24
      "type": ["string", "null"],
25
      "description": "the zip or postal code of the library"
25
      "description": "the postal code of the library"
26
    },
26
    },
27
    "branchcity": {
27
    "city": {
28
      "type": ["string", "null"],
28
      "type": ["string", "null"],
29
      "description": "the city or province of the library"
29
      "description": "the city or province of the library"
30
    },
30
    },
31
    "branchstate": {
31
    "state": {
32
      "type": ["string", "null"],
32
      "type": ["string", "null"],
33
      "description": "the reqional state of the library"
33
      "description": "the reqional state of the library"
34
    },
34
    },
35
    "branchcountry": {
35
    "country": {
36
      "type": ["string", "null"],
36
      "type": ["string", "null"],
37
      "description": "the county of the library"
37
      "description": "the county of the library"
38
    },
38
    },
39
    "branchphone": {
39
    "phone": {
40
      "type": ["string", "null"],
40
      "type": ["string", "null"],
41
      "description": "the primary phone of the library"
41
      "description": "the primary phone of the library"
42
    },
42
    },
43
    "branchfax": {
43
    "fax": {
44
      "type": ["string", "null"],
44
      "type": ["string", "null"],
45
      "description": "the fax number of the library"
45
      "description": "the fax number of the library"
46
    },
46
    },
47
    "branchemail": {
47
    "email": {
48
      "type": ["string", "null"],
48
      "type": ["string", "null"],
49
      "description": "the primary email address of the library"
49
      "description": "the primary email address of the library"
50
    },
50
    },
51
    "branchreplyto": {
51
    "reply_to_email": {
52
      "type": ["string", "null"],
52
      "type": ["string", "null"],
53
      "description": "the email to be used as a Reply-To"
53
      "description": "the email to be used as a Reply-To"
54
    },
54
    },
55
    "branchreturnpath": {
55
    "return_path_email": {
56
      "type": ["string", "null"],
56
      "type": ["string", "null"],
57
      "description": "the email to be used as Return-Path"
57
      "description": "the email to be used as Return-Path"
58
    },
58
    },
59
    "branchurl": {
59
    "url": {
60
      "type": ["string", "null"],
60
      "type": ["string", "null"],
61
      "description": "the URL for your library or branch's website"
61
      "description": "the URL for your library or branch's website"
62
    },
62
    },
63
    "issuing": {
63
    "ip": {
64
      "type": ["integer", "null"],
65
      "description": "unused in Koha"
66
    },
67
    "branchip": {
68
      "type": ["string", "null"],
64
      "type": ["string", "null"],
69
      "description": "the IP address for your library or branch"
65
      "description": "the IP address for your library or branch"
70
    },
66
    },
71
    "branchprinter": {
67
    "notes": {
72
      "type": ["string", "null"],
73
      "description": "unused in Koha"
74
    },
75
    "branchnotes": {
76
      "type": ["string", "null"],
68
      "type": ["string", "null"],
77
      "description": "notes related to your library or branch"
69
      "description": "notes related to your library or branch"
78
    },
70
    },
Lines 84-94 Link Here
84
      "type": ["string", "null"],
76
      "type": ["string", "null"],
85
      "description": "geolocation of your library"
77
      "description": "geolocation of your library"
86
    },
78
    },
87
    "marcorgcode": {
79
    "marc_org_code": {
88
        "type": [ "string", "null" ],
80
        "type": [ "string", "null" ],
89
        "description": "MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode"
81
        "description": "MARC Organization Code, see http://www.loc.gov/marc/organizations/orgshome.html, when empty defaults to syspref MARCOrgCode"
82
    },
83
    "pickup_location": {
84
        "type": "boolean",
85
        "description": "If the library can act as a pickup location"
90
    }
86
    }
91
  },
87
  },
92
  "additionalProperties": false,
88
  "additionalProperties": false,
93
  "required": ["branchcode", "branchname"]
89
  "required": ["library_id", "name"]
94
}
90
}
(-)a/api/v1/swagger/parameters.json (-2 / +2 lines)
Lines 8-15 Link Here
8
  "city_id_pp": {
8
  "city_id_pp": {
9
    "$ref": "parameters/city.json#/city_id_pp"
9
    "$ref": "parameters/city.json#/city_id_pp"
10
  },
10
  },
11
  "branchcodePathParam": {
11
  "library_id_pp": {
12
    "$ref": "parameters/library.json#/branchcodePathParam"
12
    "$ref": "parameters/library.json#/library_id_pp"
13
  },
13
  },
14
  "holdIdPathParam": {
14
  "holdIdPathParam": {
15
    "$ref": "parameters/hold.json#/holdIdPathParam"
15
    "$ref": "parameters/hold.json#/holdIdPathParam"
(-)a/api/v1/swagger/parameters/library.json (-3 / +3 lines)
Lines 1-8 Link Here
1
{
1
{
2
  "branchcodePathParam": {
2
  "library_id_pp": {
3
    "name": "branchcode",
3
    "name": "library_id",
4
    "in": "path",
4
    "in": "path",
5
    "description": "Branch identifier code",
5
    "description": "Internal library identifier",
6
    "required": true,
6
    "required": true,
7
    "type": "string"
7
    "type": "string"
8
  }
8
  }
(-)a/api/v1/swagger/paths.json (-2 / +2 lines)
Lines 23-30 Link Here
23
  "/libraries": {
23
  "/libraries": {
24
    "$ref": "paths/libraries.json#/~1libraries"
24
    "$ref": "paths/libraries.json#/~1libraries"
25
  },
25
  },
26
  "/libraries/{branchcode}": {
26
  "/libraries/{library_id}": {
27
    "$ref": "paths/libraries.json#/~1libraries~1{branchcode}"
27
    "$ref": "paths/libraries.json#/~1libraries~1{library_id}"
28
  },
28
  },
29
  "/patrons": {
29
  "/patrons": {
30
    "$ref": "paths/patrons.json#/~1patrons"
30
    "$ref": "paths/patrons.json#/~1patrons"
(-)a/api/v1/swagger/paths/libraries.json (-147 / +178 lines)
Lines 3-124 Link Here
3
    "get": {
3
    "get": {
4
      "x-mojo-to": "Library#list",
4
      "x-mojo-to": "Library#list",
5
      "operationId": "listLibrary",
5
      "operationId": "listLibrary",
6
      "tags": ["library"],
6
      "tags": [
7
      "parameters": [{
7
        "library"
8
        "name": "branchname",
8
      ],
9
        "in": "query",
9
      "parameters": [
10
        "description": "Case insensitive 'starts-with' search on name",
10
        {
11
        "required": false,
11
          "name": "name",
12
        "type": "string"
12
          "in": "query",
13
      }, {
13
          "description": "Case insensitive 'starts-with' search on name",
14
        "name": "branchaddress1",
14
          "required": false,
15
        "in": "query",
15
          "type": "string"
16
        "description": "Case insensitive 'starts-with' search on address1",
16
        },
17
        "required": false,
17
        {
18
        "type": "string"
18
          "name": "address1",
19
      }, {
19
          "in": "query",
20
        "name": "branchaddress2",
20
          "description": "Case insensitive 'starts-with' search on address1",
21
        "in": "query",
21
          "required": false,
22
        "description": "Case insensitive 'starts-with' search on address2",
22
          "type": "string"
23
        "required": false,
23
        },
24
        "type": "string"
24
        {
25
      }, {
25
          "name": "address2",
26
        "name": "branchaddress3",
26
          "in": "query",
27
        "in": "query",
27
          "description": "Case insensitive 'starts-with' search on address2",
28
        "description": "Case insensitive 'starts-with' search on address3",
28
          "required": false,
29
        "required": false,
29
          "type": "string"
30
        "type": "string"
30
        },
31
      }, {
31
        {
32
        "name": "branchzip",
32
          "name": "address3",
33
        "in": "query",
33
          "in": "query",
34
        "description": "Case insensitive 'starts-with' search on zipcode",
34
          "description": "Case insensitive 'starts-with' search on address3",
35
        "required": false,
35
          "required": false,
36
        "type": "string"
36
          "type": "string"
37
      }, {
37
        },
38
        "name": "branchcity",
38
        {
39
        "in": "query",
39
          "name": "postal_code",
40
        "description": "Case insensitive 'starts-with' search on city",
40
          "in": "query",
41
        "required": false,
41
          "description": "Case insensitive 'starts-with' search on postal code",
42
        "type": "string"
42
          "required": false,
43
      }, {
43
          "type": "string"
44
        "name": "branchstate",
44
        },
45
        "in": "query",
45
        {
46
        "description": "Case insensitive 'starts-with' search on state",
46
          "name": "city",
47
        "required": false,
47
          "in": "query",
48
        "type": "string"
48
          "description": "Case insensitive 'starts-with' search on city",
49
      }, {
49
          "required": false,
50
        "name": "branchcountry",
50
          "type": "string"
51
        "in": "query",
51
        },
52
        "description": "Case insensitive 'starts_with' search on country",
52
        {
53
        "required": false,
53
          "name": "state",
54
        "type": "string"
54
          "in": "query",
55
      }, {
55
          "description": "Case insensitive 'starts-with' search on state",
56
        "name": "branchphone",
56
          "required": false,
57
        "in": "query",
57
          "type": "string"
58
        "description": "Case insensitive 'starts_with' search on phone number",
58
        },
59
        "required": false,
59
        {
60
        "type": "string"
60
          "name": "country",
61
      }, {
61
          "in": "query",
62
        "name": "branchfax",
62
          "description": "Case insensitive 'starts_with' search on country",
63
        "in": "query",
63
          "required": false,
64
        "description": "Case insensitive 'starts_with' search on fax number",
64
          "type": "string"
65
        "required": false,
65
        },
66
        "type": "string"
66
        {
67
      }, {
67
          "name": "phone",
68
        "name": "branchemail",
68
          "in": "query",
69
        "in": "query",
69
          "description": "Case insensitive 'starts_with' search on phone number",
70
        "description": "Case insensitive 'starts_with' search on email address",
70
          "required": false,
71
        "required": false,
71
          "type": "string"
72
        "type": "string"
72
        },
73
      }, {
73
        {
74
        "name": "branchreplyto",
74
          "name": "fax",
75
        "in": "query",
75
          "in": "query",
76
        "description": "Case insensitive 'starts_with' search on Reply-To email address",
76
          "description": "Case insensitive 'starts_with' search on fax number",
77
        "required": false,
77
          "required": false,
78
        "type": "string"
78
          "type": "string"
79
      }, {
79
        },
80
        "name": "branchreturnpath",
80
        {
81
        "in": "query",
81
          "name": "email",
82
        "description": "Case insensitive 'starts_with' search on Return-Path email address",
82
          "in": "query",
83
        "required": false,
83
          "description": "Case insensitive 'starts_with' search on email address",
84
        "type": "string"
84
          "required": false,
85
      }, {
85
          "type": "string"
86
        "name": "branchurl",
86
        },
87
        "in": "query",
87
        {
88
        "description": "Case insensitive 'starts_with' search on website URL",
88
          "name": "reply_to_email",
89
        "required": false,
89
          "in": "query",
90
        "type": "string"
90
          "description": "Case insensitive 'starts_with' search on Reply-To email address",
91
      }, {
91
          "required": false,
92
        "name": "issuing",
92
          "type": "string"
93
        "in": "query",
93
        },
94
        "description": "Unused in Koha",
94
        {
95
        "required": false,
95
          "name": "return_path_email",
96
        "type": "integer"
96
          "in": "query",
97
      }, {
97
          "description": "Case insensitive 'starts_with' search on Return-Path email address",
98
        "name": "branchip",
98
          "required": false,
99
        "in": "query",
99
          "type": "string"
100
        "description": "Case insensitive 'starts_with' search on IP address",
100
        },
101
        "required": false,
101
        {
102
        "type": "string"
102
          "name": "url",
103
      }, {
103
          "in": "query",
104
        "name": "branchprinter",
104
          "description": "Case insensitive 'starts_with' search on website URL",
105
        "in": "query",
105
          "required": false,
106
        "description": "Unused in Koha",
106
          "type": "string"
107
        "required": false,
107
        },
108
        "type": "string"
108
        {
109
      }, {
109
          "name": "ip",
110
        "name": "branchnotes",
110
          "in": "query",
111
        "in": "query",
111
          "description": "Case insensitive 'starts_with' search on IP address",
112
        "description": "Case insensitive 'starts_with' search on notes",
112
          "required": false,
113
        "required": false,
113
          "type": "string"
114
        "type": "string"
114
        },
115
      }, {
115
        {
116
        "name": "opac_info",
116
          "name": "notes",
117
        "in": "query",
117
          "in": "query",
118
        "description": "Case insensitive 'starts-with' search on OPAC info",
118
          "description": "Case insensitive 'starts_with' search on notes",
119
        "required": false,
119
          "required": false,
120
        "type": "string"
120
          "type": "string"
121
      }],
121
        },
122
        {
123
          "name": "opac_info",
124
          "in": "query",
125
          "description": "Case insensitive 'starts-with' search on OPAC info",
126
          "required": false,
127
          "type": "string"
128
        }
129
      ],
122
      "produces": [
130
      "produces": [
123
        "application/json"
131
        "application/json"
124
      ],
132
      ],
Lines 149-164 Link Here
149
    "post": {
157
    "post": {
150
      "x-mojo-to": "Library#add",
158
      "x-mojo-to": "Library#add",
151
      "operationId": "addLibrary",
159
      "operationId": "addLibrary",
152
      "tags": ["library"],
160
      "tags": [
153
      "parameters": [{
161
        "library"
154
        "name": "body",
162
      ],
155
        "in": "body",
163
      "parameters": [
156
        "description": "A JSON object containing informations about the new library",
164
        {
157
        "required": true,
165
          "name": "body",
158
        "schema": {
166
          "in": "body",
159
          "$ref": "../definitions.json#/library"
167
          "description": "A JSON object containing informations about the new library",
168
          "required": true,
169
          "schema": {
170
            "$ref": "../definitions.json#/library"
171
          }
160
        }
172
        }
161
      }],
173
      ],
162
      "produces": [
174
      "produces": [
163
        "application/json"
175
        "application/json"
164
      ],
176
      ],
Lines 187-192 Link Here
187
            "$ref": "../definitions.json#/error"
199
            "$ref": "../definitions.json#/error"
188
          }
200
          }
189
        },
201
        },
202
        "409": {
203
          "description": "Conflict in creating resource",
204
          "schema": {
205
            "$ref": "../definitions.json#/error"
206
          }
207
        },
190
        "500": {
208
        "500": {
191
          "description": "Internal error",
209
          "description": "Internal error",
192
          "schema": {
210
          "schema": {
Lines 202-220 Link Here
202
      },
220
      },
203
      "x-koha-authorization": {
221
      "x-koha-authorization": {
204
        "permissions": {
222
        "permissions": {
205
          "parameters": "parameters_remaining_permissions"
223
          "parameters": "manage_libraries"
206
        }
224
        }
207
      }
225
      }
208
    }
226
    }
209
  },
227
  },
210
  "/libraries/{branchcode}": {
228
  "/libraries/{library_id}": {
211
    "get": {
229
    "get": {
212
      "x-mojo-to": "Library#get",
230
      "x-mojo-to": "Library#get",
213
      "operationId": "getLibrary",
231
      "operationId": "getLibrary",
214
      "tags": ["library"],
232
      "tags": [
233
        "library"
234
      ],
215
      "parameters": [
235
      "parameters": [
216
        {
236
        {
217
          "$ref": "../parameters.json#/branchcodePathParam"
237
          "$ref": "../parameters.json#/library_id_pp"
218
        }
238
        }
219
      ],
239
      ],
220
      "produces": [
240
      "produces": [
Lines 238-255 Link Here
238
    "put": {
258
    "put": {
239
      "x-mojo-to": "Library#update",
259
      "x-mojo-to": "Library#update",
240
      "operationId": "updateLibrary",
260
      "operationId": "updateLibrary",
241
      "tags": ["library"],
261
      "tags": [
242
      "parameters": [{
262
        "library"
243
        "$ref": "../parameters.json#/branchcodePathParam"
263
      ],
244
      }, {
264
      "parameters": [
245
        "name": "body",
265
        {
246
        "in": "body",
266
          "$ref": "../parameters.json#/library_id_pp"
247
        "description": "A JSON object containing information on the library",
267
        },
248
        "required": true,
268
        {
249
        "schema": {
269
          "name": "body",
250
          "$ref": "../definitions.json#/library"
270
          "in": "body",
271
          "description": "A JSON object containing information on the library",
272
          "required": true,
273
          "schema": {
274
            "$ref": "../definitions.json#/library"
275
          }
251
        }
276
        }
252
      }],
277
      ],
253
      "consumes": [
278
      "consumes": [
254
        "application/json"
279
        "application/json"
255
      ],
280
      ],
Lines 302-325 Link Here
302
      },
327
      },
303
      "x-koha-authorization": {
328
      "x-koha-authorization": {
304
        "permissions": {
329
        "permissions": {
305
          "parameters": "parameters_remaining_permissions"
330
          "parameters": "manage_libraries"
306
        }
331
        }
307
      }
332
      }
308
    },
333
    },
309
    "delete": {
334
    "delete": {
310
      "x-mojo-to": "Library#delete",
335
      "x-mojo-to": "Library#delete",
311
      "operationId": "deleteLibrary",
336
      "operationId": "deleteLibrary",
312
      "tags": ["library"],
337
      "tags": [
313
      "parameters": [{
338
        "library"
314
        "$ref": "../parameters.json#/branchcodePathParam"
339
      ],
315
      }],
340
      "parameters": [
341
        {
342
          "$ref": "../parameters.json#/library_id_pp"
343
        }
344
      ],
316
      "produces": [
345
      "produces": [
317
        "application/json"
346
        "application/json"
318
      ],
347
      ],
319
      "responses": {
348
      "responses": {
320
        "204": {
349
        "204": {
321
          "description": "Library deleted",
350
          "description": "Library deleted",
322
          "schema": { "type": "string" }
351
          "schema": {
352
            "type": "string"
353
          }
323
        },
354
        },
324
        "401": {
355
        "401": {
325
          "description": "Authentication required",
356
          "description": "Authentication required",
Lines 354-360 Link Here
354
      },
385
      },
355
      "x-koha-authorization": {
386
      "x-koha-authorization": {
356
        "permissions": {
387
        "permissions": {
357
          "parameters": "parameters_remaining_permissions"
388
          "parameters": "manage_libraries"
358
        }
389
        }
359
      }
390
      }
360
    }
391
    }
(-)a/api/v1/swagger/x-primitives.json (-1 / +1 lines)
Lines 7-13 Link Here
7
    "type": "integer",
7
    "type": "integer",
8
    "description": "Internal patron identifier"
8
    "description": "Internal patron identifier"
9
  },
9
  },
10
  "branchcode": {
10
  "library_id": {
11
    "type": "string",
11
    "type": "string",
12
    "description": "internally assigned library identifier",
12
    "description": "internally assigned library identifier",
13
    "maxLength": 10,
13
    "maxLength": 10,
(-)a/t/db_dependent/api/v1/libraries.t (-113 / +81 lines)
Lines 44-56 subtest 'list() tests' => sub { Link Here
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
46
    # Create test context
46
    # Create test context
47
    my $library = $builder->build( { source => 'Branch' } );
47
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
48
    my $another_library = { %$library };   # create a copy of $library but make
48
    my $another_library = $library->unblessed; # create a copy of $library but make
49
    delete $another_library->{branchcode}; # sure branchcode will be regenerated
49
    delete $another_library->{branchcode};     # sure branchcode will be regenerated
50
    $another_library = $builder->build(
50
    $another_library = $builder->build_object({ class => 'Koha::Libraries', value => $another_library });
51
        { source => 'Branch', value => $another_library } );
51
    my ( $borrowernumber, $session_id ) = create_user_and_session( { authorized => 0 } );
52
    my ( $borrowernumber, $session_id ) =
53
      create_user_and_session( { authorized => 0 } );
54
52
55
    ## Authorized user tests
53
    ## Authorized user tests
56
    my $count_of_libraries = Koha::Libraries->search->count;
54
    my $count_of_libraries = Koha::Libraries->search->count;
Lines 59-81 subtest 'list() tests' => sub { Link Here
59
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
57
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
60
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
58
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
61
    $t->request_ok($tx)
59
    $t->request_ok($tx)
62
      ->status_is(200)
60
      ->status_is( 200, 'SWAGGER3.2.2' )
63
      ->json_has('/'.($count_of_libraries-1).'/branchcode')
61
      ->json_has('/'.($count_of_libraries-1).'/library_id')
64
      ->json_hasnt('/'.($count_of_libraries).'/branchcode');
62
      ->json_hasnt('/'.($count_of_libraries).'/library_id');
65
63
66
    subtest 'query parameters' => sub {
64
    subtest 'query parameters' => sub {
67
        my @fields = qw(
65
68
        branchname       branchaddress1 branchaddress2 branchaddress3
66
        my $fields = {
69
        branchzip        branchcity     branchstate    branchcountry
67
            name              => 'branchname',
70
        branchphone      branchfax      branchemail    branchreplyto
68
            address1          => 'branchaddress1',
71
        branchreturnpath branchurl      issuing        branchip
69
            address2          => 'branchaddress2',
72
        branchprinter    branchnotes    opac_info
70
            address3          => 'branchaddress3',
73
        );
71
            postal_code       => 'branchzip',
74
        plan tests => scalar(@fields)*3;
72
            city              => 'branchcity',
75
73
            state             => 'branchstate',
76
        foreach my $field (@fields) {
74
            country           => 'branchcountry',
75
            phone             => 'branchphone',
76
            fax               => 'branchfax',
77
            email             => 'branchemail',
78
            reply_to_email    => 'branchreplyto',
79
            return_path_email => 'branchreturnpath',
80
            url               => 'branchurl',
81
            ip                => 'branchip',
82
            notes             => 'branchnotes',
83
            opac_info         => 'opac_info',
84
        };
85
86
        my $size = keys %{$fields};
87
88
        plan tests => $size * 3;
89
90
        foreach my $field ( keys %{$fields} ) {
91
            my $model_field = $fields->{ $field };
77
            $tx = $t->ua->build_tx( GET =>
92
            $tx = $t->ua->build_tx( GET =>
78
                         "/api/v1/libraries?$field=$library->{$field}" );
93
                         "/api/v1/libraries?$field=" . $library->$model_field );
79
            $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
94
            $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
80
            $tx->req->env( { REMOTE_ADDR => $remote_address } );
95
            $tx->req->env( { REMOTE_ADDR => $remote_address } );
81
            my $result =
96
            my $result =
Lines 102-119 subtest 'get() tests' => sub { Link Here
102
117
103
    $schema->storage->txn_begin;
118
    $schema->storage->txn_begin;
104
119
105
    my $library = $builder->build( { source => 'Branch' } );
120
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
106
    my ( $borrowernumber, $session_id ) =
121
    my ( $borrowernumber, $session_id ) =
107
      create_user_and_session( { authorized => 0 } );
122
      create_user_and_session( { authorized => 0 } );
108
123
109
    my $tx = $t->ua->build_tx( GET => "/api/v1/libraries/" . $library->{branchcode} );
124
    my $tx = $t->ua->build_tx( GET => "/api/v1/libraries/" . $library->branchcode );
110
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
125
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
111
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
126
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
112
    $t->request_ok($tx)
127
    $t->request_ok($tx)
113
      ->status_is(200)
128
      ->status_is( 200, 'SWAGGER3.2.2' )
114
      ->json_is($library);
129
      ->json_is( '' => Koha::REST::V1::Library::_to_api( $library->TO_JSON ), 'SWAGGER3.3.2' );
130
131
    my $non_existent_code = $library->branchcode;
132
    $library->delete;
115
133
116
    my $non_existent_code = 'non_existent'.int(rand(10000));
117
    $tx = $t->ua->build_tx( GET => "/api/v1/libraries/" . $non_existent_code );
134
    $tx = $t->ua->build_tx( GET => "/api/v1/libraries/" . $non_existent_code );
118
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
135
    $tx->req->cookies( { name => 'CGISESSID', value => $session_id } );
119
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
136
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
Lines 125-131 subtest 'get() tests' => sub { Link Here
125
};
142
};
126
143
127
subtest 'add() tests' => sub {
144
subtest 'add() tests' => sub {
128
    plan tests => 31;
145
146
    plan tests => 17;
129
147
130
    $schema->storage->txn_begin;
148
    $schema->storage->txn_begin;
131
149
Lines 133-160 subtest 'add() tests' => sub { Link Here
133
      create_user_and_session( { authorized => 0 } );
151
      create_user_and_session( { authorized => 0 } );
134
    my ( $authorized_borrowernumber, $authorized_session_id ) =
152
    my ( $authorized_borrowernumber, $authorized_session_id ) =
135
      create_user_and_session( { authorized => 1 } );
153
      create_user_and_session( { authorized => 1 } );
136
    my $library = {
154
137
        branchcode       => "LIBRARYBR1",
155
    my $library_obj = $builder->build_object({ class => 'Koha::Libraries' });
138
        branchname       => "Library Name",
156
    my $library     = Koha::REST::V1::Library::_to_api( $library_obj->TO_JSON );
139
        branchaddress1   => "Library Address1",
157
    $library_obj->delete;
140
        branchaddress2   => "Library Address2",
141
        branchaddress3   => "Library Address3",
142
        branchzip        => "Library Zipcode",
143
        branchcity       => "Library City",
144
        branchstate      => "Library State",
145
        branchcountry    => "Library Country",
146
        branchphone      => "Library Phone",
147
        branchfax        => "Library Fax",
148
        branchemail      => "Library Email",
149
        branchreplyto    => "Library Reply-To",
150
        branchreturnpath => "Library Return-Path",
151
        branchurl        => "http://library.url",
152
        issuing          => undef,                  # unused in Koha
153
        branchip         => "127.0.0.1",
154
        branchprinter    => "Library Printer",      # unused in Koha
155
        branchnotes      => "Library Notes",
156
        opac_info        => "<p>Library OPAC info</p>",
157
    };
158
158
159
    # Unauthorized attempt to write
159
    # Unauthorized attempt to write
160
    my $tx = $t->ua->build_tx( POST => "/api/v1/libraries" => json => $library );
160
    my $tx = $t->ua->build_tx( POST => "/api/v1/libraries" => json => $library );
Lines 189-218 subtest 'add() tests' => sub { Link Here
189
    $tx->req->cookies(
189
    $tx->req->cookies(
190
        { name => 'CGISESSID', value => $authorized_session_id } );
190
        { name => 'CGISESSID', value => $authorized_session_id } );
191
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
191
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
192
    my $branchcode = $t->request_ok($tx)
192
    $t->request_ok($tx)
193
      ->status_is(201)
193
      ->status_is( 201, 'SWAGGER3.2.1' )
194
      ->json_is( '/branchname'       => $library->{branchname} )
194
      ->json_is( '' => $library, 'SWAGGER3.3.1' )
195
      ->json_is( '/branchaddress1'   => $library->{branchaddress1} )
195
      ->header_is( Location => '/api/v1/libraries/' . $library->{library_id}, 'SWAGGER3.4.1' );
196
      ->json_is( '/branchaddress2'   => $library->{branchaddress2} )
197
      ->json_is( '/branchaddress3'   => $library->{branchaddress3} )
198
      ->json_is( '/branchzip'        => $library->{branchzip} )
199
      ->json_is( '/branchcity'       => $library->{branchcity} )
200
      ->json_is( '/branchstate'      => $library->{branchstate} )
201
      ->json_is( '/branchcountry'    => $library->{branchcountry} )
202
      ->json_is( '/branchphone'      => $library->{branchphone} )
203
      ->json_is( '/branchfax'        => $library->{branchfax} )
204
      ->json_is( '/branchemail'      => $library->{branchemail} )
205
      ->json_is( '/branchreplyto'    => $library->{branchreplyto} )
206
      ->json_is( '/branchreturnpath' => $library->{branchreturnpath} )
207
      ->json_is( '/branchurl'        => $library->{branchurl} )
208
      ->json_is( '/branchip'        => $library->{branchip} )
209
      ->json_is( '/branchnotes'      => $library->{branchnotes} )
210
      ->json_is( '/opac_info'        => $library->{opac_info} )
211
      ->header_is(Location => "/api/v1/libraries/$library->{branchcode}")
212
      ->tx->res->json->{branchcode};
213
196
197
    # save the library_id
198
    my $library_id = $library->{library_id};
214
    # Authorized attempt to create with null id
199
    # Authorized attempt to create with null id
215
    $library->{branchcode} = undef;
200
    $library->{library_id} = undef;
216
    $tx = $t->ua->build_tx(
201
    $tx = $t->ua->build_tx(
217
        POST => "/api/v1/libraries" => json => $library );
202
        POST => "/api/v1/libraries" => json => $library );
218
    $tx->req->cookies(
203
    $tx->req->cookies(
Lines 223-237 subtest 'add() tests' => sub { Link Here
223
      ->json_has('/errors');
208
      ->json_has('/errors');
224
209
225
    # Authorized attempt to create with existing id
210
    # Authorized attempt to create with existing id
226
    $library->{branchcode} = $branchcode;
211
    $library->{library_id} = $library_id;
227
    $tx = $t->ua->build_tx(
212
    $tx = $t->ua->build_tx(
228
        POST => "/api/v1/libraries" => json => $library );
213
        POST => "/api/v1/libraries" => json => $library );
229
    $tx->req->cookies(
214
    $tx->req->cookies(
230
        { name => 'CGISESSID', value => $authorized_session_id } );
215
        { name => 'CGISESSID', value => $authorized_session_id } );
231
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
216
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
232
    $t->request_ok($tx)
217
233
      ->status_is(400)
218
    warning_like {
234
      ->json_is('/error' => 'Library already exists');
219
        $t->request_ok($tx)
220
          ->status_is(409)
221
          ->json_has( '/error' => "Fails when trying to add an existing library_id")
222
          ->json_is(  '/conflict', 'PRIMARY' ); } # WTF
223
        qr/^DBD::mysql::st execute failed: Duplicate entry '(.*)' for key 'PRIMARY'/;
235
224
236
    $schema->storage->txn_rollback;
225
    $schema->storage->txn_rollback;
237
};
226
};
Lines 246-255 subtest 'update() tests' => sub { Link Here
246
    my ( $authorized_borrowernumber, $authorized_session_id ) =
235
    my ( $authorized_borrowernumber, $authorized_session_id ) =
247
      create_user_and_session( { authorized => 1 } );
236
      create_user_and_session( { authorized => 1 } );
248
237
249
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
238
    my $library    = $builder->build_object({ class => 'Koha::Libraries' });
239
    my $library_id = $library->branchcode;
250
240
251
    # Unauthorized attempt to update
241
    # Unauthorized attempt to update
252
    my $tx = $t->ua->build_tx( PUT => "/api/v1/libraries/$branchcode"
242
    my $tx = $t->ua->build_tx( PUT => "/api/v1/libraries/$library_id"
253
        => json => { branchname => 'New unauthorized name change' } );
243
        => json => { branchname => 'New unauthorized name change' } );
254
    $tx->req->cookies(
244
    $tx->req->cookies(
255
        { name => 'CGISESSID', value => $unauthorized_session_id } );
245
        { name => 'CGISESSID', value => $unauthorized_session_id } );
Lines 259-268 subtest 'update() tests' => sub { Link Here
259
249
260
    # Attempt partial update on a PUT
250
    # Attempt partial update on a PUT
261
    my $library_with_missing_field = {
251
    my $library_with_missing_field = {
262
        branchaddress1 => "New library address",
252
        address1 => "New library address",
263
    };
253
    };
264
254
265
    $tx = $t->ua->build_tx( PUT => "/api/v1/libraries/$branchcode" =>
255
    $tx = $t->ua->build_tx( PUT => "/api/v1/libraries/$library_id" =>
266
                            json => $library_with_missing_field );
256
                            json => $library_with_missing_field );
267
    $tx->req->cookies(
257
    $tx->req->cookies(
268
        { name => 'CGISESSID', value => $authorized_session_id } );
258
        { name => 'CGISESSID', value => $authorized_session_id } );
Lines 270-317 subtest 'update() tests' => sub { Link Here
270
    $t->request_ok($tx)
260
    $t->request_ok($tx)
271
      ->status_is(400)
261
      ->status_is(400)
272
      ->json_has( "/errors" =>
262
      ->json_has( "/errors" =>
273
          [ { message => "Missing property.", path => "/body/branchaddress2" } ]
263
          [ { message => "Missing property.", path => "/body/address2" } ]
274
      );
264
      );
275
265
276
    # Full object update on PUT
266
    my $deleted_library = $builder->build_object( { class => 'Koha::Libraries' } );
277
    my $library_with_updated_field = {
267
    my $library_with_updated_field = Koha::REST::V1::Library::_to_api( $deleted_library->TO_JSON );
278
        branchcode       => "LIBRARYBR2",
268
    $library_with_updated_field->{library_id} = $library_id;
279
        branchname       => "Library Name",
269
    $deleted_library->delete;
280
        branchaddress1   => "Library Address1",
281
        branchaddress2   => "Library Address2",
282
        branchaddress3   => "Library Address3",
283
        branchzip        => "Library Zipcode",
284
        branchcity       => "Library City",
285
        branchstate      => "Library State",
286
        branchcountry    => "Library Country",
287
        branchphone      => "Library Phone",
288
        branchfax        => "Library Fax",
289
        branchemail      => "Library Email",
290
        branchreplyto    => "Library Reply-To",
291
        branchreturnpath => "Library Return-Path",
292
        branchurl        => "http://library.url",
293
        issuing          => undef,                  # unused in Koha
294
        branchip         => "127.0.0.1",
295
        branchprinter    => "Library Printer",      # unused in Koha
296
        branchnotes      => "Library Notes",
297
        opac_info        => "<p>Library OPAC info</p>",
298
    };
299
270
300
    $tx = $t->ua->build_tx(
271
    $tx = $t->ua->build_tx( PUT => "/api/v1/libraries/$library_id" => json => $library_with_updated_field );
301
        PUT => "/api/v1/libraries/$branchcode" => json => $library_with_updated_field );
272
    $tx->req->cookies( { name => 'CGISESSID', value => $authorized_session_id } );
302
    $tx->req->cookies(
303
        { name => 'CGISESSID', value => $authorized_session_id } );
304
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
273
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
305
    $t->request_ok($tx)
274
    $t->request_ok($tx)
306
      ->status_is(200)
275
      ->status_is(200, 'SWAGGER3.2.1')
307
      ->json_is( '/branchname' => 'Library Name' );
276
      ->json_is( '' => $library_with_updated_field, 'SWAGGER3.3.3' );
308
277
309
    # Authorized attempt to write invalid data
278
    # Authorized attempt to write invalid data
310
    my $library_with_invalid_field = { %$library_with_updated_field };
279
    my $library_with_invalid_field = { %$library_with_updated_field };
311
    $library_with_invalid_field->{'branchinvalid'} = 'Library invalid';
280
    $library_with_invalid_field->{'branchinvalid'} = 'Library invalid';
312
281
313
    $tx = $t->ua->build_tx(
282
    $tx = $t->ua->build_tx(
314
        PUT => "/api/v1/libraries/$branchcode" => json => $library_with_invalid_field );
283
        PUT => "/api/v1/libraries/$library_id" => json => $library_with_invalid_field );
315
    $tx->req->cookies(
284
    $tx->req->cookies(
316
        { name => 'CGISESSID', value => $authorized_session_id } );
285
        { name => 'CGISESSID', value => $authorized_session_id } );
317
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
286
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
Lines 364-371 subtest 'delete() tests' => sub { Link Here
364
        { name => 'CGISESSID', value => $authorized_session_id } );
333
        { name => 'CGISESSID', value => $authorized_session_id } );
365
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
334
    $tx->req->env( { REMOTE_ADDR => $remote_address } );
366
    $t->request_ok($tx)
335
    $t->request_ok($tx)
367
      ->status_is(204)
336
      ->status_is(204, 'SWAGGER3.2.4')
368
      ->content_is('');
337
      ->content_is('', 'SWAGGER3.3.4');
369
338
370
    $tx = $t->ua->build_tx( DELETE => "/api/v1/libraries/$branchcode" );
339
    $tx = $t->ua->build_tx( DELETE => "/api/v1/libraries/$branchcode" );
371
    $tx->req->cookies(
340
    $tx->req->cookies(
372
- 

Return to bug 16497