diff --git a/PostText.pl b/PostText.pl index c23f721..155c42d 100755 --- a/PostText.pl +++ b/PostText.pl @@ -10,7 +10,7 @@ use Data::Dumper; # For your debugging pleasure # Load the local modules too use lib 'lib'; use PostText::Model::Thread; -use PostText::Model::Reply; +use PostText::Model::Remark; # Load Mojo plugins plugin 'Config'; @@ -26,8 +26,8 @@ helper thread => sub { state $thread = PostText::Model::Thread->new(pg => shift->pg) }; -helper reply => sub { - state $reply = PostText::Model::Reply->new(pg => shift->pg) +helper remark => sub { + state $remark = PostText::Model::Remark->new(pg => shift->pg) }; # Begin routing @@ -100,12 +100,12 @@ group { get '/:thread_id', [thread_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); + my $remarks = $c->remark->get_remarks_by_thread_id($thread_id); if (my $thread_body = %$thread{'body'}) { $c->stash( thread => $thread, - replies => $replies + remarks => $remarks ) } else { @@ -122,7 +122,7 @@ group { # Configure things app->secrets(app->config->{'secrets'}) || die $@; -app->pg->migrations->from_dir('migrations')->migrate(4); +app->pg->migrations->from_dir('migrations')->migrate(5); if (my $threads_per_page = app->config->{'threads_per_page'}) { app->thread->threads_per_page($threads_per_page); diff --git a/README.md b/README.md index b132100..9ce79a3 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,5 @@ Run the tests locally (against development environment) ## TODOs -1. Reply model needs to become Remark (to fix the error handling stuff) 1. Add hyperlink somewhere to single thread view (whoopsie) 1. Paging for replies in single thread view diff --git a/lib/PostText/Model/Remark.pm b/lib/PostText/Model/Remark.pm index 92a2019..91e9de5 100644 --- a/lib/PostText/Model/Remark.pm +++ b/lib/PostText/Model/Remark.pm @@ -22,7 +22,7 @@ sub get_remarks_by_thread_id($self, $thread_id) { TO_CHAR(remark_date, ?) AS date, remark_author AS author, remark_body AS body - FROM replies + FROM remarks WHERE thread_id = ? AND NOT hidden_status ORDER BY remark_date ASC; diff --git a/lib/PostText/Model/Reply.pm b/lib/PostText/Model/Reply.pm deleted file mode 100644 index 7199052..0000000 --- a/lib/PostText/Model/Reply.pm +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl - -package PostText::Model::Reply; - -use Mojo::Base -base, -signatures; - -has 'pg'; - -sub new($class, $pg, $pg_reference) { - bless { - $pg => $pg_reference, - replies_per_page => 5, - date_format => 'Dy Mon FMDD HH24:MI TZ YYYY' - }, $class -} - -sub get_replies_by_thread_id($self, $thread_id) { - my $date_format = %$self{'date_format'}; - - $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hashes(); - SELECT reply_id AS id, - TO_CHAR(reply_date, ?) 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 -} - -1; diff --git a/templates/thread_id.html.ep b/templates/thread_id.html.ep index 2e4894a..b22a3ad 100644 --- a/templates/thread_id.html.ep +++ b/templates/thread_id.html.ep @@ -11,13 +11,13 @@ <% } =%> -<% if (my $first_reply = @$replies[0]) { =%> -
- <% for my $reply (@$replies) { =%> -
-

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

-
<%= %$reply{'author'} %>
-

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

+<% if (my $first_remark = @$remarks[0]) { =%> +
+ <% for my $remark (@$remarks) { =%> +
+

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

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

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

<% } =%>