Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created October 23, 2023 13:02
Show Gist options
  • Save jjn1056/8fc5e1d429965ac2ac12b4f18c106901 to your computer and use it in GitHub Desktop.
Save jjn1056/8fc5e1d429965ac2ac12b4f18c106901 to your computer and use it in GitHub Desktop.
package Example::Schema::ResultSet::Todo;
use Example::Syntax;
use base 'Example::Schema::ResultSet';
__PACKAGE__->mk_group_accessors('simple' => qw/status/);
sub available($self) {
return $self->search_rs({status=>{'!='=>'archived'}});
}
sub newer_first($self) {
return $self->search_rs({},{order_by=>{-desc=>'id'}});
}
sub filter_by_request($self, $request) {
return $self->next::method($request)
->by_status($request->status);
}
sub by_status($self, $status = 'all') {
my $by = $status eq 'all' ? $self : $self->search_rs({status=>$status});
$by->status($status);
return $by;
}
sub get_last_page($self) {
my $new_resultset = $self->page($self->pager->last_page);
$new_resultset->status($self->status);
return $new_resultset;
}
sub new_todo($self) {
return $self->new_result(+{status=>'active'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment