Begin paged list of books on author page.

This commit is contained in:
barnold 2022-09-19 17:42:28 +01:00
parent 3c2dd9eac5
commit e2748bd642
3 changed files with 29 additions and 5 deletions

View File

@ -31,8 +31,13 @@ sub authors ($self) {
sub author ($self) {
my $id = $self->param('id');
my ($author, $book_page) = MyModel::Author->new(
rows_per_page => $self->rpp
)->find_by_id($id);
$self->render(
author => MyModel::Author->new->find_by_id($id)
author => $author,
book_page => $book_page,
pager => $book_page->pager,
);
}

View File

@ -19,11 +19,16 @@ sub get_page ($self, $page_number = 1, $name_like = undef) {
return $rs;
}
sub find_by_id ($self, $id) {
return $self->schema->resultset('Author')->find(
{ id => $id },
{ prefetch => [ "books" ] },
sub find_by_id ($self, $id, $page_number = 1) {
my $author = $self->schema->resultset('Author')->find({ id => $id });
my $book_page = $author->books_rs->search(
undef,
{ order_by => [ "me.title" ],
page => $page_number,
rows => $self->rows_per_page,
},
);
return ($author, $book_page);
}
no Moose;

View File

@ -5,3 +5,17 @@
<strong><%= $author->name %></strong>
% my $count = $author->books->count;
wrote <%= $count %> book<%= "s" if ($count > 1) %>.
<p/>
<div>
<table>
<tr>
<th>Title</th>
</tr>
% for my $book ($book_page->all) {
<tr>
<td><%= $book->title %></td>
</tr>
% }
</table>
</div>