sub
root :At(
'$path_end/...'
) Via(
'../protected'
) (
$self
,
$c
,
$user
) {
$c
->action->
next
(
my
$todos
=
$user
->todos);
}
sub
search :At(
'/...'
) Via(
'root'
) QueryModel (
$self
,
$c
,
$todos
,
$todo_query
) {
$todos
=
$todos
->filter_by_request(
$todo_query
);
$c
->action->
next
(
$todos
);
}
sub
list :Get(
''
) Via(
'search'
) (
$self
,
$c
,
$todos
) {
return
$self
->view(
list
=>
$todos
,
todo
=>
$todos
->new_todo,
);
}
sub
prepare_build :At(
'/...'
) Via(
'search'
) (
$self
,
$c
,
$todos
) {
$self
->view_for(
'list'
,
list
=>
$todos
,
todo
=>
my
$new_todo
=
$todos
->new_todo
);
$c
->action->
next
(
$new_todo
);
}
sub
build :Get(
'new'
) Via(
'prepare_build'
) (
$self
,
$c
,
$new_todo
) {
return
}
sub
create :Post(
''
) Via(
'prepare_build'
) BodyModel (
$self
,
$c
,
$new_todo
,
$bm
) {
return
$c
->view->clear_todo &&
$c
->view->set_list_to_last_page
if
$new_todo
->set_from_request(
$bm
)->valid;
}
sub
find :At(
'{:Int}/...'
) Via(
'root'
) (
$self
,
$c
,
$collection
,
$id
) {
my
$todo
=
$collection
->find(
$id
) //
$c
->detach_error(404, +{
error
=>
"Todo id $id not found"
});
$c
->action->
next
(
$todo
);
}
sub
prepare_edit :At(
'/...'
) Via(
'find'
) (
$self
,
$c
,
$todo
) {
$self
->view_for(
'edit'
,
todo
=>
$todo
);
$c
->action->
next
(
$todo
);
}
sub
edit :Get(
'edit'
) Via(
'prepare_edit'
) (
$self
,
$c
,
$todo
) {
return
}
sub
update :Patch(
''
) Via(
'prepare_edit'
) BodyModelFor(
'create'
) (
$self
,
$c
,
$todo
,
$bm
) {
return
$todo
->set_from_request(
$bm
);
}
__PACKAGE__->meta->make_immutable;