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

(-)a/Koha/REST/V1/Hold.pm (-27 / +32 lines)
Lines 28-34 use Koha::Holds; Link Here
28
use Koha::DateUtils;
28
use Koha::DateUtils;
29
29
30
sub list {
30
sub list {
31
    my ($c, $args, $cb) = @_;
31
    my $c = shift->openapi->valid_input or return;
32
32
33
    my $params = $c->req->query_params->to_hash;
33
    my $params = $c->req->query_params->to_hash;
34
    my @valid_params = Koha::Holds->_resultset->result_source->columns;
34
    my @valid_params = Koha::Holds->_resultset->result_source->columns;
Lines 37-47 sub list { Link Here
37
    }
37
    }
38
    my $holds = Koha::Holds->search($params);
38
    my $holds = Koha::Holds->search($params);
39
39
40
    return $c->$cb($holds, 200);
40
    return $c->render(status => 200, openapi => $holds);
41
}
41
}
42
42
43
sub add {
43
sub add {
44
    my ($c, $args, $cb) = @_;
44
    my $c = shift->openapi->valid_input or return;
45
45
46
    my $body = $c->req->json;
46
    my $body = $c->req->json;
47
47
Lines 52-69 sub add { Link Here
52
    my $expirationdate = $body->{expirationdate};
52
    my $expirationdate = $body->{expirationdate};
53
    my $borrower = Koha::Patrons->find($borrowernumber);
53
    my $borrower = Koha::Patrons->find($borrowernumber);
54
    unless ($borrower) {
54
    unless ($borrower) {
55
        return $c->$cb({error => "Borrower not found"}, 404);
55
        return $c->render( status  => 404,
56
                           openapi => {error => "Borrower not found"} );
56
    }
57
    }
57
58
58
    unless ($biblionumber or $itemnumber) {
59
    unless ($biblionumber or $itemnumber) {
59
        return $c->$cb({
60
        return $c->render( status => 400, openapi => {
60
            error => "At least one of biblionumber, itemnumber should be given"
61
            error => "At least one of biblionumber, itemnumber should be given"
61
        }, 400);
62
        } );
62
    }
63
    }
63
    unless ($branchcode) {
64
    unless ($branchcode) {
64
        return $c->$cb({
65
        return $c->render( status  => 400,
65
            error => "Branchcode is required"
66
                           openapi => { error => "Branchcode is required" } );
66
        }, 400);
67
    }
67
    }
68
68
69
    my $biblio;
69
    my $biblio;
Lines 71-79 sub add { Link Here
71
        my $item = Koha::Items->find( $itemnumber );
71
        my $item = Koha::Items->find( $itemnumber );
72
        $biblio = $item->biblio;
72
        $biblio = $item->biblio;
73
        if ($biblionumber and $biblionumber != $biblio->biblionumber) {
73
        if ($biblionumber and $biblionumber != $biblio->biblionumber) {
74
            return $c->$cb({
74
            return $c->render(
75
                error => "Item $itemnumber doesn't belong to biblio $biblionumber"
75
                status => 400,
76
            }, 400);
76
                openapi => {
77
                    error => "Item $itemnumber doesn't belong to biblio $biblionumber"
78
                });
77
        }
79
        }
78
        $biblionumber ||= $biblio->biblionumber;
80
        $biblionumber ||= $biblio->biblionumber;
79
    } else {
81
    } else {
Lines 86-94 sub add { Link Here
86
      : CanBookBeReserved( $borrowernumber, $biblionumber );
88
      : CanBookBeReserved( $borrowernumber, $biblionumber );
87
89
88
    unless ($can_reserve eq 'OK') {
90
    unless ($can_reserve eq 'OK') {
89
        return $c->$cb({
91
        return $c->render( status => 403, openapi => {
90
            error => "Reserve cannot be placed. Reason: $can_reserve"
92
            error => "Reserve cannot be placed. Reason: $can_reserve"
91
        }, 403);
93
        } );
92
    }
94
    }
93
95
94
    my $priority = C4::Reserves::CalculatePriority($biblionumber);
96
    my $priority = C4::Reserves::CalculatePriority($biblionumber);
Lines 104-127 sub add { Link Here
104
        $biblio->title, $itemnumber);
106
        $biblio->title, $itemnumber);
105
107
106
    unless ($reserve_id) {
108
    unless ($reserve_id) {
107
        return $c->$cb({
109
        return $c->render( status => 500, openapi => {
108
            error => "Error while placing reserve. See Koha logs for details."
110
            error => "Error while placing reserve. See Koha logs for details."
109
        }, 500);
111
        } );
110
    }
112
    }
111
113
112
    my $reserve = Koha::Holds->find($reserve_id);
114
    my $reserve = Koha::Holds->find($reserve_id);
113
115
114
    return $c->$cb($reserve, 201);
116
    return $c->render( status => 201, openapi => $reserve );
115
}
117
}
116
118
117
sub edit {
119
sub edit {
118
    my ($c, $args, $cb) = @_;
120
    my $c = shift->openapi->valid_input or return;
119
121
120
    my $reserve_id = $args->{reserve_id};
122
    my $reserve_id = $c->validation->param('reserve_id');
121
    my $hold = Koha::Holds->find( $reserve_id );
123
    my $hold = Koha::Holds->find( $reserve_id );
122
124
123
    return $c->$cb({error => "Reserve not found"}, 404)
125
    unless ($hold) {
124
        unless $hold;
126
        return $c->render( status  => 404,
127
                           openapi => {error => "Reserve not found"} );
128
    }
125
129
126
    my $body = $c->req->json;
130
    my $body = $c->req->json;
127
131
Lines 143-163 sub edit { Link Here
143
    C4::Reserves::ModReserve($params);
147
    C4::Reserves::ModReserve($params);
144
    $hold = Koha::Holds->find($reserve_id);
148
    $hold = Koha::Holds->find($reserve_id);
145
149
146
    return $c->$cb($hold, 200);
150
    return $c->render( status => 200, openapi => $hold );
147
}
151
}
148
152
149
sub delete {
153
sub delete {
150
    my ($c, $args, $cb) = @_;
154
    my $c = shift->openapi->valid_input or return;
151
155
152
    my $reserve_id = $args->{reserve_id};
156
    my $reserve_id = $c->validation->param('reserve_id');
153
    my $hold = Koha::Holds->find( $reserve_id );
157
    my $hold = Koha::Holds->find( $reserve_id );
154
158
155
    return $c->$cb({error => "Reserve not found"}, 404)
159
    unless ($hold) {
156
        unless $hold;
160
        return $c->render( status => 404, openapi => {error => "Reserve not found"} );
161
    }
157
162
158
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
163
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
159
164
160
    return $c->$cb({}, 200);
165
    return $c->render( status => 200, openapi => {} );
161
}
166
}
162
167
163
1;
168
1;
(-)a/api/v1/swagger/paths/holds.json (-2 / +89 lines)
Lines 1-6 Link Here
1
{
1
{
2
  "/holds": {
2
  "/holds": {
3
    "get": {
3
    "get": {
4
      "x-mojo-to": "Hold#list",
4
      "operationId": "listHolds",
5
      "operationId": "listHolds",
5
      "tags": ["patrons", "holds"],
6
      "tags": ["patrons", "holds"],
6
      "parameters": [
7
      "parameters": [
Lines 118-128 Link Here
118
            "$ref": "../definitions.json#/holds"
119
            "$ref": "../definitions.json#/holds"
119
          }
120
          }
120
        },
121
        },
122
        "401": {
123
          "description": "Authentication required",
124
          "schema": {
125
            "$ref": "../definitions.json#/error"
126
          }
127
        },
128
        "403": {
129
          "description": "Hold not allowed",
130
          "schema": {
131
            "$ref": "../definitions.json#/error"
132
          }
133
        },
121
        "404": {
134
        "404": {
122
          "description": "Borrower not found",
135
          "description": "Borrower not found",
123
          "schema": {
136
          "schema": {
124
            "$ref": "../definitions.json#/error"
137
            "$ref": "../definitions.json#/error"
125
          }
138
          }
139
        },
140
        "500": {
141
          "description": "Internal server error",
142
          "schema": {
143
            "$ref": "../definitions.json#/error"
144
          }
145
        },
146
        "503": {
147
          "description": "Under maintenance",
148
          "schema": {
149
            "$ref": "../definitions.json#/error"
150
          }
126
        }
151
        }
127
      },
152
      },
128
      "x-koha-authorization": {
153
      "x-koha-authorization": {
Lines 134-139 Link Here
134
      }
159
      }
135
    },
160
    },
136
    "post": {
161
    "post": {
162
      "x-mojo-to": "Hold#add",
137
      "operationId": "addHold",
163
      "operationId": "addHold",
138
      "tags": ["patrons", "holds"],
164
      "tags": ["patrons", "holds"],
139
      "parameters": [{
165
      "parameters": [{
Lines 184-189 Link Here
184
            "$ref": "../definitions.json#/error"
210
            "$ref": "../definitions.json#/error"
185
          }
211
          }
186
        },
212
        },
213
        "401": {
214
          "description": "Authentication required",
215
          "schema": {
216
            "$ref": "../definitions.json#/error"
217
          }
218
        },
187
        "403": {
219
        "403": {
188
          "description": "Hold not allowed",
220
          "description": "Hold not allowed",
189
          "schema": {
221
          "schema": {
Lines 197-203 Link Here
197
          }
229
          }
198
        },
230
        },
199
        "500": {
231
        "500": {
200
          "description": "Internal error",
232
          "description": "Internal server error",
233
          "schema": {
234
            "$ref": "../definitions.json#/error"
235
          }
236
        },
237
        "503": {
238
          "description": "Under maintenance",
201
          "schema": {
239
          "schema": {
202
            "$ref": "../definitions.json#/error"
240
            "$ref": "../definitions.json#/error"
203
          }
241
          }
Lines 213-218 Link Here
213
  },
251
  },
214
  "/holds/{reserve_id}": {
252
  "/holds/{reserve_id}": {
215
    "put": {
253
    "put": {
254
      "x-mojo-to": "Hold#edit",
216
      "operationId": "editHold",
255
      "operationId": "editHold",
217
      "tags": ["holds"],
256
      "tags": ["holds"],
218
      "parameters": [{
257
      "parameters": [{
Lines 258-268 Link Here
258
            "$ref": "../definitions.json#/error"
297
            "$ref": "../definitions.json#/error"
259
          }
298
          }
260
        },
299
        },
300
        "401": {
301
          "description": "Authentication required",
302
          "schema": {
303
            "$ref": "../definitions.json#/error"
304
          }
305
        },
306
        "403": {
307
          "description": "Hold not allowed",
308
          "schema": {
309
            "$ref": "../definitions.json#/error"
310
          }
311
        },
261
        "404": {
312
        "404": {
262
          "description": "Hold not found",
313
          "description": "Hold not found",
263
          "schema": {
314
          "schema": {
264
            "$ref": "../definitions.json#/error"
315
            "$ref": "../definitions.json#/error"
265
          }
316
          }
317
        },
318
        "500": {
319
          "description": "Internal server error",
320
          "schema": {
321
            "$ref": "../definitions.json#/error"
322
          }
323
        },
324
        "503": {
325
          "description": "Under maintenance",
326
          "schema": {
327
            "$ref": "../definitions.json#/error"
328
          }
266
        }
329
        }
267
      },
330
      },
268
      "x-koha-authorization": {
331
      "x-koha-authorization": {
Lines 274-279 Link Here
274
      }
337
      }
275
    },
338
    },
276
    "delete": {
339
    "delete": {
340
      "x-mojo-to": "Hold#delete",
277
      "operationId": "deleteHold",
341
      "operationId": "deleteHold",
278
      "tags": ["holds"],
342
      "tags": ["holds"],
279
      "parameters": [{
343
      "parameters": [{
Lines 288-298 Link Here
288
            "type": "object"
352
            "type": "object"
289
          }
353
          }
290
        },
354
        },
355
        "401": {
356
          "description": "Authentication required",
357
          "schema": {
358
            "$ref": "../definitions.json#/error"
359
          }
360
        },
361
        "403": {
362
          "description": "Hold not allowed",
363
          "schema": {
364
            "$ref": "../definitions.json#/error"
365
          }
366
        },
291
        "404": {
367
        "404": {
292
          "description": "Hold not found",
368
          "description": "Hold not found",
293
          "schema": {
369
          "schema": {
294
            "$ref": "../definitions.json#/error"
370
            "$ref": "../definitions.json#/error"
295
          }
371
          }
372
        },
373
        "500": {
374
          "description": "Internal server error",
375
          "schema": {
376
            "$ref": "../definitions.json#/error"
377
          }
378
        },
379
        "503": {
380
          "description": "Under maintenance",
381
          "schema": {
382
            "$ref": "../definitions.json#/error"
383
          }
296
        }
384
        }
297
      },
385
      },
298
      "x-koha-authorization": {
386
      "x-koha-authorization": {
299
- 

Return to bug 18137