Begin a view-author page.

This commit is contained in:
barnold 2022-09-18 17:17:30 +01:00
parent 7579138d99
commit a1aeb653bf
5 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,7 @@ sub startup ($self) {
$r->get('/logout')->to('auth#logout');
$r->get('/book/page/<page_number:num>')->to('book#index')->name('book_page');
$r->get('/author/page/<page_number:num>')->to('book#author')->name('author_page');
$r->get('/view_author/<id:num>')->to('book#view_author')->name('view_author');
# Put a route under athentication.
my $auth = $r->under(

View File

@ -26,4 +26,11 @@ sub author ($self) {
);
}
sub view_author ($self) {
my $id = $self->param('id');
$self->render(
author => MyModel::Author->new->find_by_id($id)
);
}
1;

View File

@ -19,5 +19,12 @@ 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" ] },
);
}
no Moose;
__PACKAGE__->meta->make_immutable;

View File

@ -20,7 +20,7 @@
</tr>
% for my $author ($author_page->all) {
<tr>
<td><%= $author->name %></td>
<td><%= link_to($author->name => 'view_author' => { id => $author->id}) %></td>
</tr>
% }
</table>

View File

@ -0,0 +1,5 @@
% layout 'default';
% title 'Author: ' . $author->name;
<h1>Author: <%= $author->name %></h1>
<strong><%= $author->name %></strong> wrote <%= $author->books->count %> books.