Fully implement basic thread submission

This commit is contained in:
ngoomie 2024-08-24 01:04:40 -06:00
parent c75f23b9c1
commit f0073d1f1f
3 changed files with 34 additions and 4 deletions

View File

@ -12,7 +12,7 @@ use Mojo::Base 'Mojolicious::Controller', -signatures;
sub thread_compose {
my $c = shift;
my $subf_id = $c->param('id');
my $subf_id = $c->param('id');
my $subf_cat =
$c->schema->resultset('Subforums')->cat_from_id($subf_id);
my $cat_title =
@ -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;

View File

@ -29,6 +29,11 @@ __PACKAGE__->add_columns(
post_date =>
{ data_type => 'integer',
is_nullable => 0,
},
post_body =>
{
data_type => 'text',
is_nullable => 0
}
);

View File

@ -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,
},