api: make _pager a helper

This commit is contained in:
Lucas 2023-03-10 20:41:52 +00:00
parent fa07cf5645
commit 95beb0a599
3 changed files with 7 additions and 9 deletions

View File

@ -17,6 +17,10 @@ sub startup ($self)
$self->helper(schema => sub { $self->helper(schema => sub {
state $schema = PoorBooru::Schema->connect($config->{dsn}) 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; my $r = $self->routes;

View File

@ -10,9 +10,6 @@ my $MEDIA_SEARCH_OPTS = {
rows => 5, 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) sub list ($self)
{ {
my $v = $self->validation; my $v = $self->validation;
@ -31,8 +28,8 @@ sub list ($self)
}, $paged_media->all; }, $paged_media->all;
return $self->render(json => { return $self->render(json => {
pager => _pager($paged_media->pager),
media => \@media, media => \@media,
pager => { $self->pager($paged_media->pager) },
}); });
}; };

View File

@ -14,9 +14,6 @@ my $TAGS_COUNT_VIEW_SEARCH_OPTS = {
rows => 5, 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) sub list ($self)
{ {
my $v = $self->validation; my $v = $self->validation;
@ -36,8 +33,8 @@ sub list ($self)
}, $paged_tags->all; }, $paged_tags->all;
return $self->render(json => { return $self->render(json => {
pager => _pager($paged_tags->pager),
tags => \@tags, tags => \@tags,
pager => { $self->pager($paged_tags->pager) },
}); });
}; };
@ -78,8 +75,8 @@ sub show ($self)
return $self->render(json => { return $self->render(json => {
id => $tag->tag_id, id => $tag->tag_id,
name => $tag->name, name => $tag->name,
pager => _pager($paged_media->pager),
media => \@media, media => \@media,
pager => { $self->pager($paged_media->pager) },
}); });
}; };