Add "author like" as book search criterion.

This commit is contained in:
barnold 2022-09-22 11:39:00 +01:00
parent e74686dd34
commit 3ef9852367
3 changed files with 9 additions and 4 deletions

View File

@ -13,6 +13,7 @@ sub books ($self) {
my $book_page = $book_model->get_page(
$page_number,
$self->param('title_like'),
$self->param('author_like'),
);
my $pager = $book_page->pager;
if ($page_number > $pager->last_page) {

View File

@ -9,10 +9,12 @@ sub count_all ($self) {
return $book_count;
}
sub get_page ($self, $page_number = 1, $title_like = undef) {
my $search_condition = (defined $title_like)
? { "me.title" => { ilike => "\%$title_like\%" } }
: undef;
sub get_page ($self, $page_number = 1, $title_like = undef, $author_like = undef) {
my $search_condition = {};
$search_condition->{ "me.title" } = { ilike => "\%$title_like\%" }
if (defined $title_like);
$search_condition->{ "author.name" } = { ilike => "\%$author_like\%" }
if (defined $author_like);
my $rs = $self->schema->resultset('Book')->search_rs(
$search_condition,
{ prefetch => [ "author" ],

View File

@ -6,6 +6,8 @@
%= form_for books => { page_number => 1 } => begin
%= label_for title_like => 'Title like'
%= text_field title_like => flash('title_like')
%= label_for author_like => 'Author like'
%= text_field author_like => flash('author_like')
%= submit_button "Search"
%= end