Last active
May 22, 2023 21:13
-
-
Save jjn1056/e53dc2400a0ca49664d9d042955cdecc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Camel::Controller::Dialog; | |
use Moose; | |
use MooseX::MethodAttributes; | |
use Camel::Syntax; | |
use Types::Standard qw/Int/; | |
extends 'Camel::Controller'; | |
sub root :Via('../private') At('dialog/...') ($self, $c, $user) { | |
$c->action->next(my $collection = $user->dialog); | |
} | |
sub list :GET Via('root') At('') ($self, $c, $collection) { | |
return $self->view( | |
segments => $collection, | |
new_segment => $collection->build, | |
)->set_http_ok; | |
} | |
sub create :POST Via('root') At('') BodyModel ($self, $c, $collection, $r) { | |
$Camel::PSGI::stdout = ''; | |
$Camel::PSGI::chat_process->stdin->write("@{[ $r->request ]}\n"); | |
$Camel::PSGI::loop->loop_once while $Camel::PSGI::stdout eq ''; | |
my $segment = $collection->create({ | |
request => $r->request, | |
response => $Camel::PSGI::stdout, | |
}); | |
$self->view_for('list', | |
segments => $collection, | |
new_segment => $segment->valid ? $collection->build : $segment, | |
); | |
return $segment->valid ? | |
$c->view->set_http_ok : | |
$c->view->set_http_bad_request; | |
} | |
__PACKAGE__->meta->make_immutable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment