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

(-)a/Koha/REST/V1/Checkouts.pm (+43 lines)
Lines 204-207 sub allows_renewal { Link Here
204
    };
204
    };
205
}
205
}
206
206
207
=head3 update
208
209
Update a checkout
210
211
=cut
212
213
sub update {
214
    my $c = shift->openapi->valid_input or return;
215
216
    my $checkout_id = $c->validation->param('checkout_id');
217
    my $checkout = Koha::Checkouts->find( $checkout_id );
218
219
    unless ($checkout) {
220
        return $c->render(
221
            status => 404,
222
            openapi => { error => "Checkout doesn't exist" }
223
        );
224
    }
225
226
    return try {
227
        my $params = $c->req->json;
228
        $checkout->set_from_api( $params );
229
        $checkout->store();
230
        return $c->render(
231
            status  => 200,
232
            openapi => $checkout->to_api
233
        );
234
    }
235
    catch {
236
        unless ( blessed $_ && $_->can('rethrow') ) {
237
            return $c->render(
238
                status  => 500,
239
                openapi => { error => "Something went wrong, check Koha logs for details." }
240
            );
241
        }
242
243
        return $c->render(
244
            status  => 500,
245
            openapi => { error => "$_" }
246
        );
247
    };
248
}
249
207
1;
250
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 82-87 Link Here
82
      "x-koha-embed": [
82
      "x-koha-embed": [
83
        "issuer"
83
        "issuer"
84
      ]
84
      ]
85
    },
86
    "put": {
87
      "x-mojo-to": "Checkouts#update",
88
      "operationId": "updateCheckout",
89
      "tags": ["patrons", "checkouts"],
90
      "parameters": [
91
        {
92
          "$ref": "../parameters.json#/checkout_id_pp"
93
        },
94
        {
95
          "name": "body",
96
          "in": "body",
97
          "description": "A JSON object containing information on the checkout",
98
          "required": true,
99
          "schema": {
100
            "$ref": "../definitions.json#/checkout"
101
          }
102
        }
103
      ],
104
      "produces": ["application/json"],
105
      "responses": {
106
        "200": {
107
          "description": "Updated borrower's checkout",
108
          "schema": { "$ref": "../definitions.json#/checkout" }
109
        },
110
        "403": {
111
          "description": "Access forbidden",
112
          "schema": { "$ref": "../definitions.json#/error" }
113
        },
114
        "404": {
115
          "description": "Checkout not found",
116
          "schema": { "$ref": "../definitions.json#/error" }
117
        }
118
      },
119
      "x-koha-authorization": {
120
        "permissions": {
121
          "circulate": "circulate_remaining_permissions"
122
        }
123
      }
85
    }
124
    }
86
  },
125
  },
87
  "/checkouts/{checkout_id}/renewal": {
126
  "/checkouts/{checkout_id}/renewal": {
88
- 

Return to bug 24609