Add minimum book count as authors search criterion.
This commit is contained in:
parent
3ef9852367
commit
ff61ab78a9
|
@ -36,6 +36,7 @@ sub authors ($self) {
|
|||
my $author_page = $author_model->get_page(
|
||||
$page_number,
|
||||
$self->param('name_like'),
|
||||
$self->param('minimum_book_count') + 0, # cast blank to 0
|
||||
);
|
||||
my $pager = $author_page->pager;
|
||||
if ($page_number > $pager->last_page) {
|
||||
|
|
|
@ -4,14 +4,17 @@ use Moose;
|
|||
extends 'MyModel';
|
||||
no warnings qw( experimental::signatures );
|
||||
|
||||
sub get_page ($self, $page_number = 1, $name_like = undef) {
|
||||
sub get_page ($self, $page_number = 1, $name_like = undef, $count_min = 0) {
|
||||
my $search_condition = (defined $name_like)
|
||||
? { "me.name" => { ilike => "\%$name_like\%" } }
|
||||
: undef;
|
||||
my $rs = $self->schema->resultset('Author')->search_rs(
|
||||
$search_condition,
|
||||
{ prefetch => [ "books" ],
|
||||
order_by => [ "me.name " ],
|
||||
{ join => 'books',
|
||||
select => [ 'me.id', 'me.name', { count => 'books.id', -as => 'bcount' } ],
|
||||
order_by => [ 'me.name' ],
|
||||
group_by => [ 'me.id', 'me.name' ],
|
||||
having => \[ 'count(books.id) >= ?', $count_min ],
|
||||
page => $page_number,
|
||||
rows => $self->rows_per_page,
|
||||
},
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
%= form_for authors => { page_number => 1 } => begin
|
||||
%= label_for name_like => 'Name like'
|
||||
%= text_field name_like => flash('name_like')
|
||||
%= label_for minimum_book_count => 'Wrote at least'
|
||||
<%= number_field minimum_book_count => 0,
|
||||
min => 0, maxlength => 4, size => 4 %> books.
|
||||
%= submit_button "Search"
|
||||
%= end
|
||||
|
||||
|
|
Loading…
Reference in New Issue