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

(-)a/Koha/REST/V1/Checkouts.pm (+43 lines)
Lines 241-244 sub allows_renewal { Link Here
241
    };
241
    };
242
}
242
}
243
243
244
=head3 update
245
246
Update a checkout
247
248
=cut
249
250
sub update {
251
    my $c = shift->openapi->valid_input or return;
252
253
    my $checkout_id = $c->validation->param('checkout_id');
254
    my $checkout = Koha::Checkouts->find( $checkout_id );
255
256
    unless ($checkout) {
257
        return $c->render(
258
            status => 404,
259
            openapi => { error => "Checkout doesn't exist" }
260
        );
261
    }
262
263
    return try {
264
        my $params = $c->req->json;
265
        $checkout->set_from_api( $params );
266
        $checkout->store();
267
        return $c->render(
268
            status  => 200,
269
            openapi => $checkout->to_api
270
        );
271
    }
272
    catch {
273
        unless ( blessed $_ && $_->can('rethrow') ) {
274
            return $c->render(
275
                status  => 500,
276
                openapi => { error => "Something went wrong, check Koha logs for details." }
277
            );
278
        }
279
280
        return $c->render(
281
            status  => 500,
282
            openapi => { error => "$_" }
283
        );
284
    };
285
}
286
244
1;
287
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-24 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
    "issuer_id": {
28
    "issuer_id": {
Lines 27-42 Link Here
27
    },
31
    },
28
    "checkin_date": {
32
    "checkin_date": {
29
      "type": ["string", "null"],
33
      "type": ["string", "null"],
34
      "readOnly": true,
30
      "format": "date-time",
35
      "format": "date-time",
31
      "description": "Date the item was returned"
36
      "description": "Date the item was returned"
32
    },
37
    },
33
    "last_renewed_date": {
38
    "last_renewed_date": {
34
      "type": ["string", "null"],
39
      "type": ["string", "null"],
40
      "readOnly": true,
35
      "format": "date-time",
41
      "format": "date-time",
36
      "description": "Date the item was last renewed"
42
      "description": "Date the item was last renewed"
37
    },
43
    },
38
    "renewals": {
44
    "renewals": {
39
      "type": ["integer", "null"],
45
      "type": ["integer", "null"],
46
      "readOnly": true,
40
      "description": "Number of renewals"
47
      "description": "Number of renewals"
41
    },
48
    },
42
    "unseen_renewals": {
49
    "unseen_renewals": {
Lines 45-75 Link Here
45
    },
52
    },
46
    "auto_renew": {
53
    "auto_renew": {
47
      "type": "boolean",
54
      "type": "boolean",
55
      "readOnly": true,
48
      "description": "Auto renewal"
56
      "description": "Auto renewal"
49
    },
57
    },
50
    "auto_renew_error": {
58
    "auto_renew_error": {
51
      "type": ["string", "null"],
59
      "type": ["string", "null"],
60
      "readOnly": true,
52
      "description": "Auto renewal error"
61
      "description": "Auto renewal error"
53
    },
62
    },
54
    "timestamp": {
63
    "timestamp": {
55
      "type": "string",
64
      "type": "string",
65
      "readOnly": true,
56
      "description": "Last update time"
66
      "description": "Last update time"
57
    },
67
    },
58
    "checkout_date": {
68
    "checkout_date": {
59
      "type": "string",
69
      "type": "string",
70
      "readOnly": true,
60
      "format": "date-time",
71
      "format": "date-time",
61
      "description": "Date the item was issued"
72
      "description": "Date the item was issued"
62
    },
73
    },
63
    "onsite_checkout": {
74
    "onsite_checkout": {
64
      "type": "boolean",
75
      "type": "boolean",
76
      "readOnly": true,
65
      "description": "On site checkout"
77
      "description": "On site checkout"
66
    },
78
    },
67
    "note": {
79
    "note": {
68
      "type": ["string", "null"],
80
      "type": ["string", "null"],
81
      "readOnly": true,
69
      "description": "Issue note text"
82
      "description": "Issue note text"
70
    },
83
    },
71
    "note_date": {
84
    "note_date": {
72
      "type": ["string", "null"],
85
      "type": ["string", "null"],
86
      "readOnly": true,
73
      "format": "date",
87
      "format": "date",
74
      "description": "Datetime of the issue note"
88
      "description": "Datetime of the issue note"
75
    },
89
    },
(-)a/api/v1/swagger/paths/checkouts.json (-1 / +39 lines)
Lines 80-85 Link Here
80
      "x-koha-embed": [
80
      "x-koha-embed": [
81
        "issuer"
81
        "issuer"
82
      ]
82
      ]
83
    },
84
    "put": {
85
      "x-mojo-to": "Checkouts#update",
86
      "operationId": "updateCheckout",
87
      "tags": ["patrons", "checkouts"],
88
      "parameters": [
89
        {
90
          "$ref": "../parameters.json#/checkout_id_pp"
91
        },
92
        {
93
          "name": "body",
94
          "in": "body",
95
          "description": "A JSON object containing information on the checkout",
96
          "required": true,
97
          "schema": {
98
            "$ref": "../definitions.json#/checkout"
99
          }
100
        }
101
      ],
102
      "produces": ["application/json"],
103
      "responses": {
104
        "200": {
105
          "description": "Updated borrower's checkout",
106
          "schema": { "$ref": "../definitions.json#/checkout" }
107
        },
108
        "403": {
109
          "description": "Access forbidden",
110
          "schema": { "$ref": "../definitions.json#/error" }
111
        },
112
        "404": {
113
          "description": "Checkout not found",
114
          "schema": { "$ref": "../definitions.json#/error" }
115
        }
116
      },
117
      "x-koha-authorization": {
118
        "permissions": {
119
          "circulate": "circulate_remaining_permissions"
120
        }
121
      }
83
    }
122
    }
84
  },
123
  },
85
  "/checkouts/{checkout_id}/renewal": {
124
  "/checkouts/{checkout_id}/renewal": {
86
- 

Return to bug 24609