From 79a91735748786b462b98b85783cf76309e0ca15 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 9 Mar 2023 21:14:44 +0000 Subject: [PATCH] api: change the pager output --- lib/PoorBooru/API/V0/Controller/Media.pm | 10 +++------- lib/PoorBooru/API/V0/Controller/Tags.pm | 12 ++++-------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/PoorBooru/API/V0/Controller/Media.pm b/lib/PoorBooru/API/V0/Controller/Media.pm index 05dcaa1..4c0e54c 100644 --- a/lib/PoorBooru/API/V0/Controller/Media.pm +++ b/lib/PoorBooru/API/V0/Controller/Media.pm @@ -10,12 +10,8 @@ my $MEDIA_SEARCH_OPTS = { rows => 5, }; -sub _pager_links ($c, $pager) -{ - +{ map +( $_ => ($pager->$_ and - $c->url_with->query({page => $pager->$_})) ), - qw(first_page previous_page current_page next_page last_page) } -} +my @PAGER_KEYS = qw(first_page previous_page current_page next_page last_page); +sub _pager ($p) { +{ map +( $_ => $p->$_ ), @PAGER_KEYS } } sub list ($self) { @@ -35,7 +31,7 @@ sub list ($self) }, $paged_media->all; return $self->render(json => { - pager => _pager_links($self, $paged_media->pager), + pager => _pager($paged_media->pager), media => \@media, }); }; diff --git a/lib/PoorBooru/API/V0/Controller/Tags.pm b/lib/PoorBooru/API/V0/Controller/Tags.pm index cde4e6d..4e19d60 100644 --- a/lib/PoorBooru/API/V0/Controller/Tags.pm +++ b/lib/PoorBooru/API/V0/Controller/Tags.pm @@ -14,12 +14,8 @@ my $TAGS_COUNT_VIEW_SEARCH_OPTS = { rows => 5, }; -sub _pager_links ($c, $pager) -{ - +{ map +( $_ => ($pager->$_ and - $c->url_with->query({page => $pager->$_})) ), - qw(first_page previous_page current_page next_page last_page) } -} +my @PAGER_KEYS = qw(first_page previous_page current_page next_page last_page); +sub _pager ($p) { +{ map +( $_ => $p->$_ ), @PAGER_KEYS } } sub list ($self) { @@ -40,7 +36,7 @@ sub list ($self) }, $paged_tags->all; return $self->render(json => { - pager => _pager_links($self, $paged_tags->pager), + pager => _pager($paged_tags->pager), tags => \@tags, }); }; @@ -82,7 +78,7 @@ sub show ($self) return $self->render(json => { id => $tag->tag_id, name => $tag->name, - pager => _pager_links($self, $paged_media->pager), + pager => _pager($paged_media->pager), media => \@media, }); };