Add open circs to user REST resource library_rest
authorJeff Godin <jgodin@tadl.org>
Mon, 3 Jun 2013 19:36:45 +0000 (15:36 -0400)
committerJeff Godin <jgodin@tadl.org>
Mon, 3 Jun 2013 19:36:45 +0000 (15:36 -0400)
Add open circs to user REST resource. This also includes a raw_
variant of the record, copy, and circ. This is for development
purposes and not intended for the final implementation.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm

index 05a774a..33d8ea4 100644 (file)
@@ -89,6 +89,8 @@ sub get_user {
     my $name_parts = [ $uobj->{first_given_name}, $uobj->{second_given_name}, $uobj->{family_name} ];
     my $name = join(' ', @$name_parts);
 
+    my $circs = _get_user_circs($target_user, $token);
+
     return {
         id => $target_user,
         name => $name,
@@ -99,8 +101,47 @@ sub get_user {
             holds => $user_summary->{holds}->{total},
             holds_detail =>  $user_summary->{holds},
             balance => $user_summary->{fines}->{balance_owed},
+        },
+        circs => $circs,
+    }
+}
+
+sub _get_user_circs {
+    my $user = shift;
+    my $token = shift;
+    return unless ($user && $token);
+
+    my $target_user = $user;
+
+    my $circ = OpenSRF::AppSession->create('open-ils.circ');
+
+    my $req = $circ->request(
+        'open-ils.circ.actor.user.checked_out',
+        $token,
+        $target_user
+    );
+
+    my @circs;
+
+    while (my $resp = $req->recv(timeout=>60)) {
+        # XXX: check for failure
+        my $circ = $resp->{content}->{circ};
+        my $record = $resp->{content}->{record};
+        my $copy = $resp->{content}->{copy};
+
+        push @circs, {
+            title => $record->title,
+            author => $record->author,
+            due_date => $circ->due_date,
+            barcode => $copy->barcode,
+            raw_record => $record->to_bare_hash,
+            raw_circ => $circ->to_bare_hash,
+            raw_copy => $copy->to_bare_hash,
         }
     }
+
+    return \@circs;
+
 }
 
 1;