Bug 17005: Add checked_in checkouts to REST API response
authorJosef Moravec <josef.moravec@gmail.com>
Mon, 1 Apr 2019 07:56:39 +0000 (07:56 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 8 Oct 2019 13:33:39 +0000 (14:33 +0100)
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 returned checkouts

Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/REST/V1/Checkouts.pm
Koha/Schema/Result/OldIssue.pm
api/v1/swagger/definitions/checkout.json
api/v1/swagger/paths/checkouts.json

index bb349a7..aa48d14 100644 (file)
@@ -25,6 +25,7 @@ use C4::Context;
 use C4::Circulation;
 use Koha::Checkouts;
 use Koha::IssuingRules;
+use Koha::Old::Checkouts;
 
 use Try::Tiny;
 
@@ -44,8 +45,14 @@ 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_set;
+        if ( $checked_in ) {
+            $checkouts_set = Koha::Old::Checkouts->new;
+        } else {
+            my $checkouts_set = Koha::Checkouts->new;
+        }
         my $checkouts = $c->objects->search( $checkouts_set, \&_to_model, \&_to_api );
         return $c->render( status => 200, openapi => $checkouts );
     } catch {
@@ -72,7 +79,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(
@@ -251,6 +261,7 @@ our $to_model_mapping = {
     last_renewed_date => 'lastreneweddate',
     checkout_date     => 'issuedate',
     note_date         => 'notedate',
+    checked_in        => undef,
 };
 
 1;
index 9ce3a74..f1ff5c2 100644 (file)
@@ -237,6 +237,11 @@ __PACKAGE__->belongs_to(
 # Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-10 19:55:44
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E2N2paWcCHg916100ry+2A
 
+__PACKAGE__->add_columns(
+    '+auto_renew'      => { is_boolean => 1 },
+    '+onsite_checkout' => { is_boolean => 1 }
+);
+
 __PACKAGE__->belongs_to(
     "borrower",
     "Koha::Schema::Result::Borrower",
index 83cbe1a..42b9598 100644 (file)
@@ -23,7 +23,7 @@
     },
     "checkin_date": {
       "type": ["string", "null"],
-      "format": "date",
+      "format": "date-time",
       "description": "Date the item was returned"
     },
     "last_renewed_date": {
index 7d89e3c..e0642d0 100644 (file)
         "$ref": "../parameters.json#/page"
       }, {
         "$ref": "../parameters.json#/per_page"
+      },{
+        "name": "checked_in",
+        "in": "query",
+        "description": "By default, current checkouts are returned, when this is true then checked in checkouts are returned as result.",
+        "type": "boolean"
       }],
       "produces": [
         "application/json"