Redirect to thread once thread is posted

This commit is contained in:
swag 2022-09-22 16:51:56 -04:00
parent e91c22a0f8
commit 2b8721d76f
2 changed files with 8 additions and 6 deletions

View File

@ -88,7 +88,7 @@ sub startup($self) {
$c->stash(status => 400)
}
else {
$c->thread->create(
my $new_thread_id = $c->thread->create(
$thread_author,
$thread_title,
$thread_body
@ -96,7 +96,9 @@ sub startup($self) {
$c->session(author => $thread_author);
return $c->redirect_to('list');
return $c->redirect_to(
thread_page => {thread_id => $new_thread_id}
);
}
}
@ -128,8 +130,7 @@ sub startup($self) {
$c->session(author => $remark_author);
return $c->redirect_to(
'thread_page',
{thread_id => $thread_id}
thread_page => {thread_id => $thread_id}
);
}
}

View File

@ -17,7 +17,7 @@ sub new($class, $pg, $pg_reference) {
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
my @data = ($author, $title, $body, $hidden, $flagged);
$self->pg->db->query(<<~'END_SQL', @data);
$self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'};
INSERT INTO threads (
thread_author,
thread_title,
@ -25,7 +25,8 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
hidden_status,
flagged_status
)
VALUES (?, ?, ?, ?, ?);
VALUES (?, ?, ?, ?, ?)
RETURNING thread_id;
END_SQL
}