Display replies in single thread view

This commit is contained in:
swagg boi 2022-08-20 12:42:04 -04:00
parent d73c7d5ac6
commit 17557a72a4
4 changed files with 43 additions and 7 deletions

View file

@ -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(

View file

@ -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;

View file

@ -92,4 +92,8 @@ sub get_thread_by_id($self, $thread_id) {
END_SQL
}
sub exception($self, $exception) {
say $exception
}
1;

View file

@ -1,13 +1,24 @@
% layout 'main';
% title "View Thread - #$thread->{'id'}";
<h2><%= title %></h2>
<div class="threads">
<% if (my $thread = $thread) { %>
<% if (my $thread_body = %$thread{'body'}) { =%>
<div class="threads">
<article class="thread">
<h3 class="title"><%= %$thread{'title'} %></h3>
<h4 class="date"><%= %$thread{'date'} %></h4>
<h5 class="author"><%= %$thread{'author'} %></h5>
<p class="body"><%= %$thread{'body'} %></p>
<p class="body"><%= $thread_body %></p>
</article>
<% } =%>
</div>
</div>
<% } =%>
<% if (my $first_reply = @$replies[0]) { =%>
<div class="replies">
<% for my $reply (@$replies) { =%>
<article class="reply">
<h4 class="date"><%= %$reply{'date'} %></h4>
<h5 class="author"><%= %$reply{'author'} %></h5>
<p class="body"><%= %$reply{'body'} %></p>
</article>
<% } =%>
</div>
<% } =%>