Rename some things for clarity.
This commit is contained in:
parent
a1aeb653bf
commit
3dc4410342
|
@ -17,9 +17,9 @@ sub startup ($self) {
|
|||
$r->get('/auth')->to('auth#index');
|
||||
$r->post('/login')->to('auth#login');
|
||||
$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');
|
||||
$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');
|
||||
|
||||
# Put a route under athentication.
|
||||
my $auth = $r->under(
|
||||
|
|
|
@ -3,7 +3,7 @@ use Mojo::Base 'Mojolicious::Controller', -signatures;
|
|||
use MyModel::Book;
|
||||
use MyModel::Author;
|
||||
|
||||
sub index ($self) {
|
||||
sub books ($self) {
|
||||
my $page_number = $self->param('page_number') // 1;
|
||||
my $book_model = MyModel::Book->new;
|
||||
my $book_page = $book_model->get_page($page_number, $self->param('title_like'));
|
||||
|
@ -13,7 +13,7 @@ sub index ($self) {
|
|||
);
|
||||
}
|
||||
|
||||
sub author ($self) {
|
||||
sub authors ($self) {
|
||||
my $page_number = $self->param('page_number') // 1;
|
||||
my $author_model = MyModel::Author->new;
|
||||
my $author_page = $author_model->get_page(
|
||||
|
@ -26,7 +26,7 @@ sub author ($self) {
|
|||
);
|
||||
}
|
||||
|
||||
sub view_author ($self) {
|
||||
sub author ($self) {
|
||||
my $id = $self->param('id');
|
||||
$self->render(
|
||||
author => MyModel::Author->new->find_by_id($id)
|
||||
|
|
|
@ -11,7 +11,8 @@ $t->get_ok('/account')->status_is(302);
|
|||
$t->get_ok('/auth')->status_is(200)->content_like(qr/login/i);
|
||||
$t->post_ok('/login' => form => { logname => 'Dobby' });
|
||||
$t->get_ok('/')->status_is(200)->content_like(qr/dobby/i);
|
||||
$t->get_ok('/book/page/1')->status_is(200)->content_like(qr/[[:digit:]] books found/i);
|
||||
$t->get_ok('/books/1')->status_is(200)->content_like(qr/[[:digit:]] books found/i);
|
||||
$t->get_ok('/authors/1')->status_is(200)->content_like(qr/[[:digit:]] authors found/i);
|
||||
$t->get_ok('/logout')->status_is(302);
|
||||
# Can't do "content_unlike()" so check it offers login now.
|
||||
$t->get_ok('/')->status_is(200)->content_like(qr/login/i);
|
||||
|
|
|
@ -1,29 +1,5 @@
|
|||
% layout 'default';
|
||||
% title 'Authors';
|
||||
<h1>Author page</h1>
|
||||
% title 'Author: ' . $author->name;
|
||||
<h1>Author: <%= $author->name %></h1>
|
||||
|
||||
<%# On a new search, reset the page number to 1. %>
|
||||
%= form_for author_page => { page_number => 1 } => begin
|
||||
%= label_for name_like => 'Name like'
|
||||
%= text_field name_like => flash('name_like')
|
||||
%= submit_button "Search"
|
||||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> authors found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
% for my $author ($author_page->all) {
|
||||
<tr>
|
||||
<td><%= link_to($author->name => 'view_author' => { id => $author->id}) %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
</div>
|
||||
|
||||
%= include '_page-navigation'
|
||||
<strong><%= $author->name %></strong> wrote <%= $author->books->count %> books.
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
% layout 'default';
|
||||
% title 'Authors';
|
||||
<h1>Author page</h1>
|
||||
|
||||
<%# On a new search, reset the page number to 1. %>
|
||||
%= form_for authors => { page_number => 1 } => begin
|
||||
%= label_for name_like => 'Name like'
|
||||
%= text_field name_like => flash('name_like')
|
||||
%= submit_button "Search"
|
||||
%= end
|
||||
|
||||
<p/>
|
||||
<%= $pager->total_entries %> authors found.
|
||||
|
||||
<p/>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
</tr>
|
||||
% for my $author ($author_page->all) {
|
||||
<tr>
|
||||
<td><%= link_to($author->name => 'author' => { id => $author->id}) %></td>
|
||||
</tr>
|
||||
% }
|
||||
</table>
|
||||
</div>
|
||||
|
||||
%= include '_page-navigation'
|
|
@ -3,7 +3,7 @@
|
|||
<h1>Book page</h1>
|
||||
|
||||
<%# On a new search, reset the page number to 1. %>
|
||||
%= form_for book_page => { page_number => 1 } => begin
|
||||
%= form_for books => { page_number => 1 } => begin
|
||||
%= label_for title_like => 'Title like'
|
||||
%= text_field title_like => flash('title_like')
|
||||
%= submit_button "Search"
|
|
@ -1,5 +0,0 @@
|
|||
% layout 'default';
|
||||
% title 'Author: ' . $author->name;
|
||||
<h1>Author: <%= $author->name %></h1>
|
||||
|
||||
<strong><%= $author->name %></strong> wrote <%= $author->books->count %> books.
|
|
@ -5,8 +5,8 @@
|
|||
<p>Pages that don't require login:</p>
|
||||
|
||||
<p><%= link_to("About" => 'about') %></p>
|
||||
<p><%= link_to("Books" => 'book_page' => { page_number => 1 }) %></p>
|
||||
<p><%= link_to("Authors" => 'author_page' => { page_number => 1 }) %></p>
|
||||
<p><%= link_to("Books" => 'books' => { page_number => 1 }) %></p>
|
||||
<p><%= link_to("Authors" => 'authors' => { page_number => 1 }) %></p>
|
||||
|
||||
<p>For this, you'll need to log in, then MyApp will redirect you:</p>
|
||||
<p><%= link_to("Account" => 'account') %></p>
|
||||
|
|
Loading…
Reference in New Issue