Implement single thread view
This commit is contained in:
parent
3bec9a71f1
commit
cffa4bfa9d
22
PostText.pl
22
PostText.pl
|
@ -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 $@;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
13
templates/thread_id.html.ep
Normal file
13
templates/thread_id.html.ep
Normal 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>
|
Loading…
Reference in a new issue