Bugzilla – Attachment 156885 Details for
Bug 24401
REST API: Check-in
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24401: Add API endpoint to check in items
Bug-24401-Add-API-endpoint-to-check-in-items.patch (text/plain), 4.63 KB, created by
Aleisha Amohia
on 2023-10-12 01:40:05 UTC
(
hide
)
Description:
Bug 24401: Add API endpoint to check in items
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2023-10-12 01:40:05 UTC
Size:
4.63 KB
patch
obsolete
>From 5b568f4e581c3d2b9c50c9f32979b06f95a874de Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Thu, 12 Oct 2023 01:35:41 +0000 >Subject: [PATCH] Bug 24401: Add API endpoint to check in items > >This adds a POST /checkouts/{checkout_id}/checkin/{library_id} endpoint for returning checkouts > >To test: > >- Run unit tests in t/db_dependent/api/v1/checkouts.t >- Make POST request to http://yourlibrary/api/v1/checkouts/{checkout_id}/checkin/{library_id} where checkout_id is the ID of the checkout you're returning and library_id is the branchcode of the return library >- Observe returned data > - 400 incorrect params > - 403 cannot be returned > - 404 missing params > - 201 item checked in > >Sponsored-by: Auckland University of Technology >--- > Koha/REST/V1/Checkouts.pm | 46 ++++++++++++++++++++++++++++- > api/v1/swagger/paths/checkouts.yaml | 36 ++++++++++++++++++++++ > api/v1/swagger/swagger.yaml | 2 ++ > 3 files changed, 83 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index a7749f1210e..2bc76e764e2 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -22,7 +22,7 @@ use Mojo::JSON; > > use C4::Auth qw( haspermission ); > use C4::Context; >-use C4::Circulation qw( AddIssue AddRenewal CanBookBeRenewed ); >+use C4::Circulation qw( AddIssue AddRenewal CanBookBeRenewed AddReturn ); > use Koha::Checkouts; > use Koha::Old::Checkouts; > use Koha::Token; >@@ -420,4 +420,48 @@ sub allows_renewal { > }; > } > >+=head3 checkin >+ >+Return a checkout (check in) >+ >+=cut >+ >+sub checkin { >+ my $c = shift->openapi->valid_input or return; >+ >+ my $checkout_id = $c->param('checkout_id'); >+ my $checkout = Koha::Checkouts->find($checkout_id); >+ >+ unless ($checkout) { >+ return $c->render( >+ status => 400, >+ openapi => { error => "Checkout doesn't exist" } >+ ); >+ } >+ >+ my $item = $checkout->item; >+ >+ my $library_id = $c->param('library_id'); >+ >+ return try { >+ my ( $return_success, $return_messages, $old_checkout ) = AddReturn( $item->barcode, $library_id ); >+ >+ $c->res->headers->location( $c->req->url->to_string ); >+ >+ if ($return_success) { >+ return $c->render( >+ status => 201, >+ openapi => $old_checkout->to_api >+ ); >+ } else { >+ return $c->render( >+ status => 403, >+ openapi => $return_messages >+ ); >+ } >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml >index cd07123aff1..c94658c168e 100644 >--- a/api/v1/swagger/paths/checkouts.yaml >+++ b/api/v1/swagger/paths/checkouts.yaml >@@ -411,3 +411,39 @@ > description: Under maintenance > schema: > $ref: "../swagger.yaml#/definitions/error" >+"/checkouts/{checkout_id}/checkin/{library_id}": >+ post: >+ x-mojo-to: Checkouts#checkin >+ operationId: returnsCheckout >+ tags: >+ - checkouts >+ summary: Return a checkout (check in) >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/checkout_id_pp" >+ - $ref: "../swagger.yaml#/parameters/library_id_pp" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Checkout returned (checked in) >+ schema: >+ $ref: "../swagger.yaml#/definitions/checkout" >+ "400": >+ description: Missing or wrong parameters >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Cannot return checkout >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "404": >+ description: Checkout not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "503": >+ description: Under maintenance >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ circulate: circulate_remaining_permissions >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index c52d03462ac..92ea728b939 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -205,6 +205,8 @@ paths: > $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewals" > "/checkouts/{checkout_id}/renewal": > $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal" >+ "/checkouts/{checkout_id}/checkin/{library_id}": >+ $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1checkin~1{library_id}" > "/checkouts/availability": > $ref: "./paths/checkouts.yaml#/~1checkouts~1availability" > /circulation-rules/kinds: >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24401
:
151109
|
151181
|
151182
|
151183
|
151184
|
152717
|
154428
|
154429
|
154430
|
154431
|
156884
|
156885
|
168337
|
172764
|
173189
|
173194
|
176190
|
176191