Fully implement basic thread submission
This commit is contained in:
parent
c75f23b9c1
commit
f0073d1f1f
|
@ -34,10 +34,11 @@ sub thread_submit {
|
|||
|
||||
my $thread_title = $c->param('thread-title');
|
||||
my $post_content = $c->param('post-content');
|
||||
my $post_time = time;
|
||||
my $subf_id = $c->param('id');
|
||||
my $post_time = time;
|
||||
|
||||
my $catch_error;
|
||||
my $thread_id;
|
||||
|
||||
# make sure post data is valid
|
||||
try {
|
||||
|
@ -45,11 +46,34 @@ sub thread_submit {
|
|||
or die "Please fill both the title and post content fields"
|
||||
} catch ($catch_error) {
|
||||
$c->flash(error => $catch_error);
|
||||
$c->redirect_to('board/:id/new')
|
||||
$c->redirect_to('/board/:id/new')
|
||||
}
|
||||
|
||||
# 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;
|
||||
|
|
|
@ -29,6 +29,11 @@ __PACKAGE__->add_columns(
|
|||
post_date =>
|
||||
{ data_type => 'integer',
|
||||
is_nullable => 0,
|
||||
},
|
||||
post_body =>
|
||||
{
|
||||
data_type => 'text',
|
||||
is_nullable => 0
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ __PACKAGE__->table('threads');
|
|||
__PACKAGE__->add_columns(
|
||||
thread_id =>
|
||||
{ data_type => 'integer',
|
||||
is_numeric => 1,
|
||||
is_auto_increment => 1,
|
||||
is_nullable => 0,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue