diff --git a/lib/PostText.pm b/lib/PostText.pm index 12b7c99..c7415c3 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -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} ); } } diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index a2cd6da..afb735e 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -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 }