From 95beb0a599e662ccdca37955b91afdc0a588415b Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 10 Mar 2023 20:41:52 +0000 Subject: [PATCH] api: make _pager a helper --- lib/PoorBooru/API/V0.pm | 4 ++++ lib/PoorBooru/API/V0/Controller/Media.pm | 5 +---- lib/PoorBooru/API/V0/Controller/Tags.pm | 7 ++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/PoorBooru/API/V0.pm b/lib/PoorBooru/API/V0.pm index 31a156a..40100f8 100644 --- a/lib/PoorBooru/API/V0.pm +++ b/lib/PoorBooru/API/V0.pm @@ -17,6 +17,10 @@ sub startup ($self) $self->helper(schema => sub { state $schema = PoorBooru::Schema->connect($config->{dsn}) }); + $self->helper(pager => sub ($, $dbp) { + map +( $_ => $dbp->$_ ), qw(first_page previous_page + current_page next_page last_page) + }); my $r = $self->routes; diff --git a/lib/PoorBooru/API/V0/Controller/Media.pm b/lib/PoorBooru/API/V0/Controller/Media.pm index 4c0e54c..7558760 100644 --- a/lib/PoorBooru/API/V0/Controller/Media.pm +++ b/lib/PoorBooru/API/V0/Controller/Media.pm @@ -10,9 +10,6 @@ my $MEDIA_SEARCH_OPTS = { rows => 5, }; -my @PAGER_KEYS = qw(first_page previous_page current_page next_page last_page); -sub _pager ($p) { +{ map +( $_ => $p->$_ ), @PAGER_KEYS } } - sub list ($self) { my $v = $self->validation; @@ -31,8 +28,8 @@ sub list ($self) }, $paged_media->all; return $self->render(json => { - pager => _pager($paged_media->pager), media => \@media, + pager => { $self->pager($paged_media->pager) }, }); }; diff --git a/lib/PoorBooru/API/V0/Controller/Tags.pm b/lib/PoorBooru/API/V0/Controller/Tags.pm index 4e19d60..7452bd3 100644 --- a/lib/PoorBooru/API/V0/Controller/Tags.pm +++ b/lib/PoorBooru/API/V0/Controller/Tags.pm @@ -14,9 +14,6 @@ my $TAGS_COUNT_VIEW_SEARCH_OPTS = { rows => 5, }; -my @PAGER_KEYS = qw(first_page previous_page current_page next_page last_page); -sub _pager ($p) { +{ map +( $_ => $p->$_ ), @PAGER_KEYS } } - sub list ($self) { my $v = $self->validation; @@ -36,8 +33,8 @@ sub list ($self) }, $paged_tags->all; return $self->render(json => { - pager => _pager($paged_tags->pager), tags => \@tags, + pager => { $self->pager($paged_tags->pager) }, }); }; @@ -78,8 +75,8 @@ sub show ($self) return $self->render(json => { id => $tag->tag_id, name => $tag->name, - pager => _pager($paged_media->pager), media => \@media, + pager => { $self->pager($paged_media->pager) }, }); };