From 25060f4f7f3a2934fe1fd5c3607b4bde16ffbe3a Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 1 Apr 2019 07:56:39 +0000 Subject: [PATCH] Bug 17005: Add checked_in checkouts to REST API response This patch implements parameter 'checked_in' on checkouts endpoint to enable getting circulation history. Test plan: 1) Apply the patch and restart plack 2) Use your favorite REST API tester and play with /checkouts endpoint: - use it without checked_in parameter - use checked_in=1 for getting all (not only current) checkouts --- Koha/REST/V1/Checkouts.pm | 13 ++++++++++++- Koha/Schema/Result/OldIssue.pm | 5 +++++ api/v1/swagger/definitions/checkout.json | 2 +- api/v1/swagger/paths/checkouts.json | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index 0e3b60e445..9c0a292a15 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -23,6 +23,7 @@ use C4::Auth qw( haspermission ); use C4::Context; use C4::Circulation; use Koha::Checkouts; +use Koha::Old::Checkouts; use Try::Tiny; @@ -42,9 +43,15 @@ List Koha::Checkout objects sub list { my $c = shift->openapi->valid_input or return; + my $checked_in = $c->validation->param('checked_in'); try { my $checkouts_set = Koha::Checkouts->new; my $checkouts = $c->objects->search( $checkouts_set, \&_to_model, \&_to_api ); + if ( $checked_in ) { + my $old_checkouts_set = Koha::Old::Checkouts->new; + my $old_checkouts = $c->objects->search( $old_checkouts_set, \&_to_model, \&_to_api ); + $checkouts = [ @$checkouts, @$old_checkouts ]; + } return $c->render( status => 200, openapi => $checkouts ); } catch { if ( $_->isa('DBIx::Class::Exception') ) { @@ -70,7 +77,10 @@ get one checkout sub get { my $c = shift->openapi->valid_input or return; - my $checkout = Koha::Checkouts->find( $c->validation->param('checkout_id') ); + my $checkout_id = $c->validation->param('checkout_id'); + my $checkout = Koha::Checkouts->find( $checkout_id ); + $checkout = Koha::Old::Checkouts->find( $checkout_id ) + unless ($checkout); unless ($checkout) { return $c->render( @@ -206,6 +216,7 @@ our $to_model_mapping = { last_renewed_date => 'lastreneweddate', checkout_date => 'issuedate', note_date => 'notedate', + checked_in => undef, }; 1; diff --git a/Koha/Schema/Result/OldIssue.pm b/Koha/Schema/Result/OldIssue.pm index df84a07e32..f92314276e 100644 --- a/Koha/Schema/Result/OldIssue.pm +++ b/Koha/Schema/Result/OldIssue.pm @@ -236,6 +236,11 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-07-23 13:51:40 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1f688Osvh/sxg2P/qffZ2g +__PACKAGE__->add_columns( + '+auto_renew' => { is_boolean => 1 }, + '+onsite_checkout' => { is_boolean => 1 } +); + __PACKAGE__->belongs_to( "borrower", "Koha::Schema::Result::Borrower", diff --git a/api/v1/swagger/definitions/checkout.json b/api/v1/swagger/definitions/checkout.json index 83cbe1a447..42b9598843 100644 --- a/api/v1/swagger/definitions/checkout.json +++ b/api/v1/swagger/definitions/checkout.json @@ -23,7 +23,7 @@ }, "checkin_date": { "type": ["string", "null"], - "format": "date", + "format": "date-time", "description": "Date the item was returned" }, "last_renewed_date": { diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json index 6293401b8b..3a4a624c86 100644 --- a/api/v1/swagger/paths/checkouts.json +++ b/api/v1/swagger/paths/checkouts.json @@ -6,6 +6,11 @@ "tags": ["patrons", "checkouts"], "parameters": [{ "$ref": "../parameters.json#/patron_id_qp" + },{ + "name": "checked_in", + "in": "query", + "description": "By default, only current checkout are returned, when this is true, all checkouts (current and checked in) are returned as result.", + "type": "boolean" }], "produces": [ "application/json" -- 2.11.0