Compare commits
2 Commits
3c2dd9eac5
...
f2418a1e59
Author | SHA1 | Date |
---|---|---|
barnold | f2418a1e59 | |
barnold | e2748bd642 |
|
@ -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(
|
||||
|
|
|
@ -30,9 +30,14 @@ 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, $page_number);
|
||||
$self->render(
|
||||
author => MyModel::Author->new->find_by_id($id)
|
||||
author => $author,
|
||||
book_page => $book_page,
|
||||
pager => $book_page->pager,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -2,6 +2,20 @@
|
|||
% 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>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
</tr>
|
||||
% for my $book ($book_page->all) {
|
||||
<tr>
|
||||
<td><%= $book->title %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
</div>
|
||||
|
||||
%= include '_page-navigation', items_name => 'books';
|
||||
|
|
Loading…
Reference in New Issue