31 lines
865 B
Perl
31 lines
865 B
Perl
package MyModel::Book;
|
|
use feature qw( signatures );
|
|
use Moose;
|
|
extends 'MyModel';
|
|
no warnings qw( experimental::signatures );
|
|
|
|
sub count_all ($self) {
|
|
my $book_count = $self->schema->resultset('Book')->count;
|
|
return $book_count;
|
|
}
|
|
|
|
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" ],
|
|
order_by => [ "me.title " ],
|
|
page => $page_number,
|
|
rows => $self->rows_per_page,
|
|
},
|
|
);
|
|
return $rs;
|
|
}
|
|
|
|
no Moose;
|
|
__PACKAGE__->meta->make_immutable;
|