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

(-)a/Koha/REST/V1/Hold.pm (-27 / +28 lines)
Lines 27-46 use Koha::Holds; Link Here
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
28
29
sub list {
29
sub list {
30
    my ($c, $args, $cb) = @_;
30
    my $c = shift->openapi->valid_input or return;
31
31
32
    my $params = $c->req->query_params->to_hash;
32
    my $params = $c->req->query_params->to_hash;
33
    my @valid_params = Koha::Holds->_resultset->result_source->columns;
33
    my @valid_params = Koha::Holds->_resultset->result_source->columns;
34
    foreach my $key (keys %$params) {
34
    foreach my $key (keys %$params) {
35
        delete $params->{$key} unless grep { $key eq $_ } @valid_params;
35
        delete $params->{$key} unless grep { $key eq $_ } @valid_params;
36
    }
36
    }
37
    my $holds = Koha::Holds->search($params)->unblessed;
37
    my $holds = Koha::Holds->search($params);
38
38
39
    return $c->$cb($holds, 200);
39
    return $c->render(status => 200, openapi => $holds);
40
}
40
}
41
41
42
sub add {
42
sub add {
43
    my ($c, $args, $cb) = @_;
43
    my $c = shift->openapi->valid_input or return;
44
44
45
    my $body = $c->req->json;
45
    my $body = $c->req->json;
46
46
Lines 51-76 sub add { Link Here
51
    my $expirationdate = $body->{expirationdate};
51
    my $expirationdate = $body->{expirationdate};
52
    my $borrower = Koha::Patrons->find($borrowernumber);
52
    my $borrower = Koha::Patrons->find($borrowernumber);
53
    unless ($borrower) {
53
    unless ($borrower) {
54
        return $c->$cb({error => "Borrower not found"}, 404);
54
        return $c->render( status  => 404,
55
                           openapi => {error => "Borrower not found"} );
55
    }
56
    }
56
57
57
    unless ($biblionumber or $itemnumber) {
58
    unless ($biblionumber or $itemnumber) {
58
        return $c->$cb({
59
        return $c->render( status => 400, openapi => {
59
            error => "At least one of biblionumber, itemnumber should be given"
60
            error => "At least one of biblionumber, itemnumber should be given"
60
        }, 400);
61
        } );
61
    }
62
    }
62
    unless ($branchcode) {
63
    unless ($branchcode) {
63
        return $c->$cb({
64
        return $c->render( status  => 400,
64
            error => "Branchcode is required"
65
                           openapi => { error => "Branchcode is required" } );
65
        }, 400);
66
    }
66
    }
67
67
68
    if ($itemnumber) {
68
    if ($itemnumber) {
69
        my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber);
69
        my $item_biblionumber = C4::Biblio::GetBiblionumberFromItemnumber($itemnumber);
70
        if ($biblionumber and $biblionumber != $item_biblionumber) {
70
        if ($biblionumber and $biblionumber != $item_biblionumber) {
71
            return $c->$cb({
71
            return $c->render( status => 400, openapi => {
72
                error => "Item $itemnumber doesn't belong to biblio $biblionumber"
72
                error => "Item $itemnumber doesn't belong to biblio $biblionumber"
73
            }, 400);
73
            } );
74
        }
74
        }
75
        $biblionumber ||= $item_biblionumber;
75
        $biblionumber ||= $item_biblionumber;
76
    }
76
    }
Lines 83-91 sub add { Link Here
83
      : CanBookBeReserved( $borrowernumber, $biblionumber );
83
      : CanBookBeReserved( $borrowernumber, $biblionumber );
84
84
85
    unless ($can_reserve eq 'OK') {
85
    unless ($can_reserve eq 'OK') {
86
        return $c->$cb({
86
        return $c->render( status => 403, openapi => {
87
            error => "Reserve cannot be placed. Reason: $can_reserve"
87
            error => "Reserve cannot be placed. Reason: $can_reserve"
88
        }, 403);
88
        } );
89
    }
89
    }
90
90
91
    my $priority = C4::Reserves::CalculatePriority($biblionumber);
91
    my $priority = C4::Reserves::CalculatePriority($biblionumber);
Lines 101-124 sub add { Link Here
101
        $biblio->{title}, $itemnumber);
101
        $biblio->{title}, $itemnumber);
102
102
103
    unless ($reserve_id) {
103
    unless ($reserve_id) {
104
        return $c->$cb({
104
        return $c->render( status => 500, openapi => {
105
            error => "Error while placing reserve. See Koha logs for details."
105
            error => "Error while placing reserve. See Koha logs for details."
106
        }, 500);
106
        } );
107
    }
107
    }
108
108
109
    my $reserve = C4::Reserves::GetReserve($reserve_id);
109
    my $hold = Koha::Holds->find($reserve_id);
110
110
111
    return $c->$cb($reserve, 201);
111
    return $c->render( status => 201, openapi => $hold );
112
}
112
}
113
113
114
sub edit {
114
sub edit {
115
    my ($c, $args, $cb) = @_;
115
    my $c = shift->openapi->valid_input or return;
116
116
117
    my $reserve_id = $args->{reserve_id};
117
    my $reserve_id = $c->validation->param('reserve_id');
118
    my $reserve = C4::Reserves::GetReserve($reserve_id);
118
    my $reserve = C4::Reserves::GetReserve($reserve_id);
119
119
120
    unless ($reserve) {
120
    unless ($reserve) {
121
        return $c->$cb({error => "Reserve not found"}, 404);
121
        return $c->render( status  => 404,
122
                           openapi => {error => "Reserve not found"} );
122
    }
123
    }
123
124
124
    my $body = $c->req->json;
125
    my $body = $c->req->json;
Lines 138-161 sub edit { Link Here
138
        suspend_until => $suspend_until,
139
        suspend_until => $suspend_until,
139
    };
140
    };
140
    C4::Reserves::ModReserve($params);
141
    C4::Reserves::ModReserve($params);
141
    $reserve = C4::Reserves::GetReserve($reserve_id);
142
    $reserve = Koha::Holds->find($reserve_id);
142
143
143
    return $c->$cb($reserve, 200);
144
    return $c->render( status => 200, openapi => $reserve );
144
}
145
}
145
146
146
sub delete {
147
sub delete {
147
    my ($c, $args, $cb) = @_;
148
    my $c = shift->openapi->valid_input or return;
148
149
149
    my $reserve_id = $args->{reserve_id};
150
    my $reserve_id = $c->validation->param('reserve_id');
150
    my $reserve = C4::Reserves::GetReserve($reserve_id);
151
    my $reserve = C4::Reserves::GetReserve($reserve_id);
151
152
152
    unless ($reserve) {
153
    unless ($reserve) {
153
        return $c->$cb({error => "Reserve not found"}, 404);
154
        return $c->render( status => 404, openapi => {error => "Reserve not found"} );
154
    }
155
    }
155
156
156
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
157
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
157
158
158
    return $c->$cb({}, 200);
159
    return $c->render( status => 200, openapi => {} );
159
}
160
}
160
161
161
1;
162
1;
(-)a/Koha/Schema/Result/Reserve.pm (+5 lines)
Lines 334-337 __PACKAGE__->belongs_to( Link Here
334
  },
334
  },
335
);
335
);
336
336
337
__PACKAGE__->add_columns(
338
    '+lowestPriority' => { is_boolean => 1 },
339
    '+suspend' => { is_boolean => 1 }
340
);
341
337
1;
342
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