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

(-)a/Koha/REST/V1/Checkouts.pm (+43 lines)
Lines 227-230 sub allows_renewal { Link Here
227
    );
227
    );
228
}
228
}
229
229
230
=head3 update
231
232
Update a checkout
233
234
=cut
235
236
sub update {
237
    my $c = shift->openapi->valid_input or return;
238
239
    my $checkout_id = $c->validation->param('checkout_id');
240
    my $checkout = Koha::Checkouts->find( $checkout_id );
241
242
    unless ($checkout) {
243
        return $c->render(
244
            status => 404,
245
            openapi => { error => "Checkout doesn't exist" }
246
        );
247
    }
248
249
    return try {
250
        my $params = $c->req->json;
251
        $checkout->set_from_api( $params );
252
        $checkout->store();
253
        return $c->render(
254
            status  => 200,
255
            openapi => $checkout->to_api
256
        );
257
    }
258
    catch {
259
        unless ( blessed $_ && $_->can('rethrow') ) {
260
            return $c->render(
261
                status  => 500,
262
                openapi => { error => "Something went wrong, check Koha logs for details." }
263
            );
264
        }
265
266
        return $c->render(
267
            status  => 500,
268
            openapi => { error => "$_" }
269
        );
270
    };
271
}
272
230
1;
273
1;
(-)a/api/v1/swagger/definitions/checkout.json (+14 lines)
Lines 3-15 Link Here
3
  "properties": {
3
  "properties": {
4
    "checkout_id": {
4
    "checkout_id": {
5
      "type": "integer",
5
      "type": "integer",
6
      "readOnly": true,
6
      "description": "internally assigned checkout identifier"
7
      "description": "internally assigned checkout identifier"
7
    },
8
    },
8
    "patron_id": {
9
    "patron_id": {
10
      "readOnly": true,
9
      "$ref": "../x-primitives.json#/patron_id"
11
      "$ref": "../x-primitives.json#/patron_id"
10
    },
12
    },
11
    "item_id": {
13
    "item_id": {
12
      "type": "integer",
14
      "type": "integer",
15
      "readOnly": true,
13
      "description": "internal identifier of checked out item"
16
      "description": "internal identifier of checked out item"
14
    },
17
    },
15
    "due_date": {
18
    "due_date": {
Lines 19-67 Link Here
19
    },
22
    },
20
    "library_id": {
23
    "library_id": {
21
      "type": ["string", "null"],
24
      "type": ["string", "null"],
25
      "readOnly": true,
22
      "description": "code of the library the item was checked out"
26
      "description": "code of the library the item was checked out"
23
    },
27
    },
24
    "checkin_date": {
28
    "checkin_date": {
25
      "type": ["string", "null"],
29
      "type": ["string", "null"],
30
      "readOnly": true,
26
      "format": "date-time",
31
      "format": "date-time",
27
      "description": "Date the item was returned"
32
      "description": "Date the item was returned"
28
    },
33
    },
29
    "last_renewed_date": {
34
    "last_renewed_date": {
30
      "type": ["string", "null"],
35
      "type": ["string", "null"],
36
      "readOnly": true,
31
      "format": "date-time",
37
      "format": "date-time",
32
      "description": "Date the item was last renewed"
38
      "description": "Date the item was last renewed"
33
    },
39
    },
34
    "renewals": {
40
    "renewals": {
35
      "type": ["integer", "null"],
41
      "type": ["integer", "null"],
42
      "readOnly": true,
36
      "description": "Number of renewals"
43
      "description": "Number of renewals"
37
    },
44
    },
38
    "auto_renew": {
45
    "auto_renew": {
39
      "type": "boolean",
46
      "type": "boolean",
47
      "readOnly": true,
40
      "description": "Auto renewal"
48
      "description": "Auto renewal"
41
    },
49
    },
42
    "auto_renew_error": {
50
    "auto_renew_error": {
43
      "type": ["string", "null"],
51
      "type": ["string", "null"],
52
      "readOnly": true,
44
      "description": "Auto renewal error"
53
      "description": "Auto renewal error"
45
    },
54
    },
46
    "timestamp": {
55
    "timestamp": {
47
      "type": "string",
56
      "type": "string",
57
      "readOnly": true,
48
      "description": "Last update time"
58
      "description": "Last update time"
49
    },
59
    },
50
    "checkout_date": {
60
    "checkout_date": {
51
      "type": "string",
61
      "type": "string",
62
      "readOnly": true,
52
      "format": "date-time",
63
      "format": "date-time",
53
      "description": "Date the item was issued"
64
      "description": "Date the item was issued"
54
    },
65
    },
55
    "onsite_checkout": {
66
    "onsite_checkout": {
56
      "type": "boolean",
67
      "type": "boolean",
68
      "readOnly": true,
57
      "description": "On site checkout"
69
      "description": "On site checkout"
58
    },
70
    },
59
    "note": {
71
    "note": {
60
      "type": ["string", "null"],
72
      "type": ["string", "null"],
73
      "readOnly": true,
61
      "description": "Issue note text"
74
      "description": "Issue note text"
62
    },
75
    },
63
    "note_date": {
76
    "note_date": {
64
      "type": ["string", "null"],
77
      "type": ["string", "null"],
78
      "readOnly": true,
65
      "format": "date",
79
      "format": "date",
66
      "description": "Datetime of the issue note"
80
      "description": "Datetime of the issue note"
67
    }
81
    }
(-)a/api/v1/swagger/paths/checkouts.json (-1 / +39 lines)
Lines 74-79 Link Here
74
          "circulate": "circulate_remaining_permissions"
74
          "circulate": "circulate_remaining_permissions"
75
        }
75
        }
76
      }
76
      }
77
    },
78
    "put": {
79
      "x-mojo-to": "Checkouts#update",
80
      "operationId": "updateCheckout",
81
      "tags": ["patrons", "checkouts"],
82
      "parameters": [
83
        {
84
          "$ref": "../parameters.json#/checkout_id_pp"
85
        },
86
        {
87
          "name": "body",
88
          "in": "body",
89
          "description": "A JSON object containing information on the checkout",
90
          "required": true,
91
          "schema": {
92
            "$ref": "../definitions.json#/checkout"
93
          }
94
        }
95
      ],
96
      "produces": ["application/json"],
97
      "responses": {
98
        "200": {
99
          "description": "Updated borrower's checkout",
100
          "schema": { "$ref": "../definitions.json#/checkout" }
101
        },
102
        "403": {
103
          "description": "Access forbidden",
104
          "schema": { "$ref": "../definitions.json#/error" }
105
        },
106
        "404": {
107
          "description": "Checkout not found",
108
          "schema": { "$ref": "../definitions.json#/error" }
109
        }
110
      },
111
      "x-koha-authorization": {
112
        "permissions": {
113
          "circulate": "circulate_remaining_permissions"
114
        }
115
      }
77
    }
116
    }
78
  },
117
  },
79
  "/checkouts/{checkout_id}/renewal": {
118
  "/checkouts/{checkout_id}/renewal": {
80
- 

Return to bug 24609