<%= %$thread{'title'} %>
<%= %$thread{'date'} %>
<%= %$thread{'author'} %>
-<%= %$thread{'body'} %>
+<%= $thread_body %>
diff --git a/PostText.pl b/PostText.pl index 222a758..a4c97a9 100755 --- a/PostText.pl +++ b/PostText.pl @@ -100,9 +100,13 @@ group { get '/:thread_id', [message_id => qr/[0-9]+/], sub ($c) { my $thread_id = $c->param('thread_id'); my $thread = $c->thread->get_thread_by_id($thread_id); + my $replies = $c->reply->get_replies_by_thread_id($thread_id); - if (%$thread{'body'}) { - $c->stash(thread => $thread) + if (my $thread_body = %$thread{'body'}) { + $c->stash( + thread => $thread, + replies => $replies + ) } else { $c->stash( diff --git a/lib/PostText/Model/Reply.pm b/lib/PostText/Model/Reply.pm index d94001b..f9fee91 100644 --- a/lib/PostText/Model/Reply.pm +++ b/lib/PostText/Model/Reply.pm @@ -13,4 +13,21 @@ sub new($class, $pg, $pg_reference) { }, $class } +sub get_replies_by_thread_id($self, $thread_id) { + $self->pg->db->query(<<~'END_SQL', $thread_id)->hashes() + SELECT reply_id AS id, + TO_CHAR(reply_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date, + reply_author AS author, + reply_body AS body + FROM replies + WHERE thread_id = ? + AND NOT hidden_status + ORDER BY reply_date ASC; + END_SQL +} + +sub exception($self, $exception) { + say $exception +} + 1; diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index debb1f6..80fd38d 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -92,4 +92,8 @@ sub get_thread_by_id($self, $thread_id) { END_SQL } +sub exception($self, $exception) { + say $exception +} + 1; diff --git a/templates/thread_id.html.ep b/templates/thread_id.html.ep index a935430..2e4894a 100644 --- a/templates/thread_id.html.ep +++ b/templates/thread_id.html.ep @@ -1,13 +1,24 @@ % layout 'main'; % title "View Thread - #$thread->{'id'}";
<%= %$thread{'body'} %>
+<%= $thread_body %>
<%= %$reply{'body'} %>
+