diff --git a/PostText.pl b/PostText.pl index ef5c1ef..222a758 100755 --- a/PostText.pl +++ b/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 $@; diff --git a/README.md b/README.md index fac8bc4..069dce7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 5210862..debb1f6 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -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; diff --git a/templates/thread_id.html.ep b/templates/thread_id.html.ep new file mode 100644 index 0000000..be4fcad --- /dev/null +++ b/templates/thread_id.html.ep @@ -0,0 +1,13 @@ +% layout 'main'; +% title 'View Threads'; +

<%= title %>

+
+ <% if (my $thread = $thread) { %> +
+

<%= %$thread{'title'} %>

+

<%= %$thread{'date'} %>

+
<%= %$thread{'author'} %>
+

<%= %$thread{'body'} %>

+
+ <% } =%> +