From: Jeff Godin Date: Mon, 3 Jun 2013 19:36:45 +0000 (-0400) Subject: Add open circs to user REST resource X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Flibrary_rest;p=evergreen%2Ftadl.git Add open circs to user REST resource 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 --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm b/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm index 05a774a4c0..33d8ea4991 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/LibraryREST.pm @@ -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;