LP#1951318: API call to retrieve (publicly-visible) carousel contents
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Fri, 5 Nov 2021 23:41:55 +0000 (16:41 -0700)
committerMike Rylander <mrylander@gmail.com>
Thu, 24 Mar 2022 16:51:27 +0000 (12:51 -0400)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/Carousel.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm

index 9e9fa61..cc5d0ec 100644 (file)
@@ -19,6 +19,50 @@ my $logger = "OpenSRF::Utils::Logger";
 sub initialize { return 1; }
 
 __PACKAGE__->register_method(
+    method  => "get_carousel_contents",
+    api_name    => "open-ils.actor.carousel.get_contents",
+    authoritative => 1,
+    notes        => <<"    NOTES");
+        Given a carousel ID, returns the carousel name and any publicly-visible
+        bibs from the associated bucket
+        PARAMS(carousel_id)
+    NOTES
+
+sub get_carousel_contents {
+    my($self, $client, $id) = @_;
+    my $e = new_editor();
+    my $carousel = $e->retrieve_container_carousel($id);
+    my $ret = {
+        id   => $id,
+        name => $carousel->name
+    };
+    my $q = {
+        select => { bre => ['id'], mfde => [{ column => 'value', alias => 'title' }] },
+        from   => {
+            bre => {
+                cbrebi => {
+                    join => {
+                        cbreb => {
+                            join => { cc => {} }
+                        }
+                    }
+                },
+                mfde => {}
+            }
+        },
+        where  => {
+            '+cc' => { id => $id },
+            '+bre' => { deleted => 'f' },
+            '+mfde' => { name => 'title' }
+        },
+        order_by => {cbrebi => ['pos','create_time']}
+    };
+    my $r = $e->json_query($q);
+    $ret->{bibs} = $r;
+    return $ret;
+}
+
+__PACKAGE__->register_method(
     method  => "retrieve_carousels_at_org",
     api_name    => "open-ils.actor.carousel.retrieve_by_org",
     authoritative => 1,
index 9b0279d..6d5432e 100644 (file)
@@ -430,7 +430,6 @@ sub load_common {
     $self->load_org_util_funcs;
     $self->load_perm_funcs;
 
-    # FIXME - move carousel helpers to a separate file
     $ctx->{get_visible_carousels} = sub {
         my $org_unit = $self->ctx->{carousel_loc} || $self->ctx->{physical_loc} || $self->cgi->param('loc') || $self->ctx->{aou_tree}->()->id;
         return $U->simplereq(
@@ -441,36 +440,11 @@ sub load_common {
     };
     $ctx->{get_carousel} = sub {
         my $id = shift;
-
-        my $carousel = $e->retrieve_container_carousel($id);
-        my $ret = {
-            id   => $id,
-            name => $carousel->name
-        };
-        my $q = {
-            select => { bre => ['id'], mfde => [{ column => 'value', alias => 'title' }] },
-            from   => {
-                bre => {
-                    cbrebi => {
-                        join => {
-                            cbreb => {
-                                join => { cc => {} }
-                            }
-                        }
-                    },
-                    mfde => {}
-                }
-            },
-            where  => {
-                '+cc' => { id => $id },
-                '+bre' => { deleted => 'f' },
-                '+mfde' => { name => 'title' }
-            },
-            order_by => {cbrebi => ['pos','create_time']}
-        };
-        my $r = $e->json_query($q);
-        $ret->{bibs} = $r;
-        return $ret;
+        return $U->simplereq(
+            'open-ils.actor',
+            'open-ils.actor.carousel.get_contents',
+            $id
+        );
     };
 
     $ctx->{fetch_display_fields} = sub {