Implement single thread view

This commit is contained in:
swaggboi 2022-08-19 23:11:20 -04:00
parent 3bec9a71f1
commit cffa4bfa9d
4 changed files with 49 additions and 1 deletions

View File

@ -93,6 +93,28 @@ any [qw{GET POST}], '/post', sub ($c) {
return $c->render();
};
# Thread
group {
under '/thread';
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);
if (%$thread{'body'}) {
$c->stash(thread => $thread)
}
else {
$c->stash(
thread => [],
status => 404
)
}
$c->render();
};
};
# Configure things
app->secrets(app->config->{'secrets'}) || die $@;

View File

@ -24,7 +24,8 @@ Run the tests locally (against development environment)
## TODOs
1. Make a view for single threads(!!)
1. Retrieve replies in the single thread view
1. Paging for replies in single thread view
1. Default 'threads per page' is broken if config file isn't correct
(should pick up the default value wtf)
1. Pick a date format

View File

@ -80,4 +80,16 @@ sub get_thread_count($self) {
END_SQL
}
sub get_thread_by_id($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)->hashes->[0]
SELECT thread_id AS id,
TO_CHAR(thread_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY') AS date,
thread_author AS author,
thread_title AS title,
thread_body AS body
FROM threads
WHERE thread_id = ?;
END_SQL
}
1;

View File

@ -0,0 +1,13 @@
% layout 'main';
% title 'View Threads';
<h2><%= title %></h2>
<div class="threads">
<% if (my $thread = $thread) { %>
<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>
</article>
<% } =%>
</div>