Bugzilla – Attachment 151109 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: REST API: Check-in WIP
-Bug-24401-REST-API-Check-in-WIP.patch (text/plain), 7.34 KB, created by
Danyon Sewell
on 2023-05-12 04:07:02 UTC
(
hide
)
Description:
Bug 24401: REST API: Check-in WIP
Filename:
MIME Type:
Creator:
Danyon Sewell
Created:
2023-05-12 04:07:02 UTC
Size:
7.34 KB
patch
obsolete
>From e17fdd9999f06b956ca05471e41d5c088a0e8323 Mon Sep 17 00:00:00 2001 >From: danyonsewell <danyonsewell@catalyst.net.nz> >Date: Fri, 12 May 2023 03:02:09 +0000 >Subject: [PATCH] Bug 24401: REST API: Check-in WIP > > Updating files to include API endpoints for check-ins > > Test plan: > > 1) Apply bug 23336 as there are dependencies in there required for this to work > > 2) Apply this patch > > 3) Run unit tests in t/db_dependent/api/v1/checkouts.t > > 4) Make POST request to http://yourlibrary/api/v1/checkouts with request body >containing 'item_id' & 'library_id' properties. >- Observe returned data and HTTP code > - 201 for item checked in > - 403 for check in not allowed > - 409 for Item not found > - 400 for item not checked out > >Sponsored-by: Auckland University of Technology >--- > Koha/REST/V1/Checkouts.pm | 61 +++++++++++++++++++++++++++++ > api/v1/swagger/paths/checkouts.yaml | 30 ++++++++++++++ > api/v1/swagger/swagger.yaml | 8 ++++ > t/db_dependent/api/v1/checkouts.t | 60 ++++++++++++++++++++++++++++ > 4 files changed, 159 insertions(+) > >diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm >index 96950f6d21..0cc1defa6a 100644 >--- a/Koha/REST/V1/Checkouts.pm >+++ b/Koha/REST/V1/Checkouts.pm >@@ -259,6 +259,67 @@ sub add { > }; > } > >+=head3 delete >+ >+Removing the checked out item from the issues table and adding it to the >+old_issues table >+ >+=cut >+ >+sub delete { >+ >+ my $c = shift->openapi->valid_input or return; >+ >+ my $body = $c->validation->param('body'); >+ my $item_id = $body->{item_id}; >+ >+ return try { >+ my $item = Koha::Items->find($item_id); >+ unless ($item) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => 'Item not found' >+ } >+ ); >+ } >+ my $checkout = Koha::Checkouts->find({ itemnumber => $item_id }); >+ unless ( $checkout ) { >+ return $c->render( >+ status => 400, >+ openapi => { error => "Item not checked out" } >+ ); >+ } >+ my $library_id = $c->validation->output->{library_id}; >+ unless ( $library_id ) { >+ $library_id = $checkout->patron->branchcode; >+ } >+ my $library = Koha::Libraries->find( $library_id ); >+ >+ try { >+ my $barcode = $item->barcode; >+ my ( $returned ) = C4::Circulation::AddReturn( $barcode, $library_id ); >+ >+ unless ( $returned ) { >+ return $c->render( >+ status => 403, >+ openapi => { error => "Checkin not allowed" } >+ ); >+ } >+ >+ $c->res->headers->location( $c->req->url->to_string ); >+ return $c->render( >+ status => 201, >+ openapi => $item->to_api >+ ); >+ } >+ catch { >+ $c->unhandled_exception($_); >+ }; >+ } >+ } >+ >+ > =head3 get_renewals > > List Koha::Checkout::Renewals >diff --git a/api/v1/swagger/paths/checkouts.yaml b/api/v1/swagger/paths/checkouts.yaml >index afe6e5660c..8f90c568b4 100644 >--- a/api/v1/swagger/paths/checkouts.yaml >+++ b/api/v1/swagger/paths/checkouts.yaml >@@ -123,6 +123,36 @@ > x-koha-authorization: > permissions: > circulate: circulate_remaining_permissions >+ delete: >+ x-mojo-to: Checkout#delete >+ operationId: deletecheckout >+ tags: >+ - checkouts >+ - items >+ summary: Check in an item >+ parameters: >+ - $ref: "../swagger.yaml#/parameters/item_id_pp" >+ - $ref: "../swagger.yaml#/parameters/library_id_qp" >+ produces: >+ - application/json >+ responses: >+ "201": >+ description: Item returned >+ "400": >+ description: Item not checked out >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "403": >+ description: Checkin not allowed >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Item not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ circulate: circulate_remaining_permissions > "/checkouts/{checkout_id}": > get: > x-mojo-to: Checkouts#get >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 914cccf586..1e95e3e414 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -199,6 +199,8 @@ paths: > $ref: "./paths/checkouts.yaml#/~1checkouts~1{checkout_id}~1renewal" > "/checkouts/availability": > $ref: "./paths/checkouts.yaml#/~1checkouts~1availability" >+ "/checkouts/{item_id}": >+ $ref: "./paths/checkouts.yaml#/~1checkouts~1{item_id}" > /circulation-rules/kinds: > $ref: ./paths/circulation-rules.yaml#/~1circulation-rules~1kinds > /cities: >@@ -528,6 +530,12 @@ parameters: > in: query > name: item_id > type: integer >+ library_id_qp: >+ description: Internal library identifier. If not provided, will ues checkout patron's home library >+ in: query >+ name: library_id >+ required: false >+ type: string > job_id_pp: > description: Job internal identifier > in: path >diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t >index 89ebb5862b..ec9b44051f 100755 >--- a/t/db_dependent/api/v1/checkouts.t >+++ b/t/db_dependent/api/v1/checkouts.t >@@ -408,3 +408,63 @@ subtest 'add checkout' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'delete checkout' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2 } >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ my $unauth_password = 'thePassword000'; >+ $patron->set_password( >+ { password => $unauth_password, skip_validattion => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ my $branch = $builder->build_sample_branch; >+ my $library_id = $branch->id; >+ my $item1 = $builder->build_sample_item; >+ my $item1_id = $item1->id; >+ >+ >+ $t->delete_ok( >+ "//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => >+ { item_id => $item1_id, library_id => $library_id } )->status_is(403) >+ ->json_is( >+ { >+ error => "checkin not allowed", >+ required_permissions => >+ { circulate => "circulate_remaining_permissions" } >+ } >+ ); >+ >+ $t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => >+ { item_id => $item1_id, patron_id => $library_id } )->status_is(400) >+ ->json_is( >+ '/error' => 'Item not checked out' ); >+ >+ AddIssue( $patron, $item1->barcode ); >+ $t->delete_ok( "//$userid:$password@/api/v1/checkouts" => json => >+ { item_id => $item1_id, patron_id => $library_id } )->status_is(201); >+ >+ $item1->delete; >+ $t->delete_ok( "//$userid:$password@/api/v1/checkouts/" => json => >+ { item_id => $item1_id, patron_id => $library_id } )->status_is(409) >+ ->json_is( >+ '/error' => 'Item not found' ); >+ $schema->storage->txn_rollback; >+}; >-- >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