Author page shows paged list of author's books.

This commit is contained in:
barnold 2022-09-19 17:52:48 +01:00
parent e2748bd642
commit f2418a1e59
3 changed files with 6 additions and 6 deletions

View File

@ -47,7 +47,7 @@ sub startup ($self) {
$r->get('/logout')->to('auth#logout');
$r->get('/books/<page_number:num>')->to('book#books')->name('books');
$r->get('/authors/<page_number:num>')->to('book#authors')->name('authors');
$r->get('/author/<id:num>')->to('book#author')->name('author');
$r->get('/author/<id:num>/<page_number:num>')->to('book#author')->name('author');
# Put a route under athentication.
my $auth = $r->under(

View File

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

View File

@ -2,9 +2,7 @@
% title 'Author: ' . $author->name;
<h1><%= title %></h1>
<strong><%= $author->name %></strong>
% my $count = $author->books->count;
wrote <%= $count %> book<%= "s" if ($count > 1) %>.
Books by <strong><%= $author->name %></strong>
<p/>
<div>
@ -19,3 +17,5 @@ wrote <%= $count %> book<%= "s" if ($count > 1) %>.
% }
</table>
</div>
%= include '_page-navigation', items_name => 'books';