Fully implement basic thread submission
This commit is contained in:
parent
c75f23b9c1
commit
f0073d1f1f
|
@ -12,7 +12,7 @@ use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
sub thread_compose {
|
sub thread_compose {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
|
|
||||||
my $subf_id = $c->param('id');
|
my $subf_id = $c->param('id');
|
||||||
my $subf_cat =
|
my $subf_cat =
|
||||||
$c->schema->resultset('Subforums')->cat_from_id($subf_id);
|
$c->schema->resultset('Subforums')->cat_from_id($subf_id);
|
||||||
my $cat_title =
|
my $cat_title =
|
||||||
|
@ -34,10 +34,11 @@ sub thread_submit {
|
||||||
|
|
||||||
my $thread_title = $c->param('thread-title');
|
my $thread_title = $c->param('thread-title');
|
||||||
my $post_content = $c->param('post-content');
|
my $post_content = $c->param('post-content');
|
||||||
my $post_time = time;
|
|
||||||
my $subf_id = $c->param('id');
|
my $subf_id = $c->param('id');
|
||||||
|
my $post_time = time;
|
||||||
|
|
||||||
my $catch_error;
|
my $catch_error;
|
||||||
|
my $thread_id;
|
||||||
|
|
||||||
# make sure post data is valid
|
# make sure post data is valid
|
||||||
try {
|
try {
|
||||||
|
@ -45,11 +46,34 @@ sub thread_submit {
|
||||||
or die "Please fill both the title and post content fields"
|
or die "Please fill both the title and post content fields"
|
||||||
} catch ($catch_error) {
|
} catch ($catch_error) {
|
||||||
$c->flash(error => $catch_error);
|
$c->flash(error => $catch_error);
|
||||||
$c->redirect_to('board/:id/new')
|
$c->redirect_to('/board/:id/new')
|
||||||
}
|
}
|
||||||
|
|
||||||
# now send it
|
# now send it
|
||||||
|
try {
|
||||||
|
my $thread = $c->schema->resultset('Threads')->create({
|
||||||
|
thread_title => $thread_title,
|
||||||
|
thread_subf => $subf_id
|
||||||
|
})
|
||||||
|
or die "Server error, thread creation failed";
|
||||||
|
$thread->update
|
||||||
|
or die "Server error, thread creation failed";
|
||||||
|
$thread_id = $thread->id;
|
||||||
|
print $thread_id;
|
||||||
|
my $post = $c->schema->resultset('Posts')->create({
|
||||||
|
user_id => $c->session('user_id'),
|
||||||
|
thread_id => $thread_id,
|
||||||
|
post_date => time,
|
||||||
|
post_body => $post_content
|
||||||
|
})
|
||||||
|
or die "Thread was created successfully, but without an OP";
|
||||||
|
$post->update
|
||||||
|
or die "Thread was created successfully, but without an OP";
|
||||||
|
} catch ($catch_error) {
|
||||||
|
$c->flash(error => $catch_error);
|
||||||
|
$c->redirect_to('/board/:id/new')
|
||||||
|
};
|
||||||
|
$c->redirect_to('/thread/' . $thread_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -29,6 +29,11 @@ __PACKAGE__->add_columns(
|
||||||
post_date =>
|
post_date =>
|
||||||
{ data_type => 'integer',
|
{ data_type => 'integer',
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
|
},
|
||||||
|
post_body =>
|
||||||
|
{
|
||||||
|
data_type => 'text',
|
||||||
|
is_nullable => 0
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ __PACKAGE__->table('threads');
|
||||||
__PACKAGE__->add_columns(
|
__PACKAGE__->add_columns(
|
||||||
thread_id =>
|
thread_id =>
|
||||||
{ data_type => 'integer',
|
{ data_type => 'integer',
|
||||||
|
is_numeric => 1,
|
||||||
is_auto_increment => 1,
|
is_auto_increment => 1,
|
||||||
is_nullable => 0,
|
is_nullable => 0,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue