Implement Remark model

This commit is contained in:
swagg boi 2022-08-22 15:50:10 -04:00
parent 403b0cea26
commit 7b74dbe787
5 changed files with 14 additions and 47 deletions

View file

@ -10,7 +10,7 @@ use Data::Dumper; # For your debugging pleasure
# Load the local modules too # Load the local modules too
use lib 'lib'; use lib 'lib';
use PostText::Model::Thread; use PostText::Model::Thread;
use PostText::Model::Reply; use PostText::Model::Remark;
# Load Mojo plugins # Load Mojo plugins
plugin 'Config'; plugin 'Config';
@ -26,8 +26,8 @@ helper thread => sub {
state $thread = PostText::Model::Thread->new(pg => shift->pg) state $thread = PostText::Model::Thread->new(pg => shift->pg)
}; };
helper reply => sub { helper remark => sub {
state $reply = PostText::Model::Reply->new(pg => shift->pg) state $remark = PostText::Model::Remark->new(pg => shift->pg)
}; };
# Begin routing # Begin routing
@ -100,12 +100,12 @@ group {
get '/:thread_id', [thread_id => qr/[0-9]+/], sub ($c) { get '/:thread_id', [thread_id => qr/[0-9]+/], sub ($c) {
my $thread_id = $c->param('thread_id'); my $thread_id = $c->param('thread_id');
my $thread = $c->thread->get_thread_by_id($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'}) { if (my $thread_body = %$thread{'body'}) {
$c->stash( $c->stash(
thread => $thread, thread => $thread,
replies => $replies remarks => $remarks
) )
} }
else { else {
@ -122,7 +122,7 @@ group {
# Configure things # Configure things
app->secrets(app->config->{'secrets'}) || die $@; 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'}) { if (my $threads_per_page = app->config->{'threads_per_page'}) {
app->thread->threads_per_page($threads_per_page); app->thread->threads_per_page($threads_per_page);

View file

@ -24,6 +24,5 @@ Run the tests locally (against development environment)
## TODOs ## TODOs
1. Reply model needs to become Remark (to fix the error handling stuff)
1. Add hyperlink somewhere to single thread view (whoopsie) 1. Add hyperlink somewhere to single thread view (whoopsie)
1. Paging for replies in single thread view 1. Paging for replies in single thread view

View file

@ -22,7 +22,7 @@ sub get_remarks_by_thread_id($self, $thread_id) {
TO_CHAR(remark_date, ?) AS date, TO_CHAR(remark_date, ?) AS date,
remark_author AS author, remark_author AS author,
remark_body AS body remark_body AS body
FROM replies FROM remarks
WHERE thread_id = ? WHERE thread_id = ?
AND NOT hidden_status AND NOT hidden_status
ORDER BY remark_date ASC; ORDER BY remark_date ASC;

View file

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

View file

@ -11,13 +11,13 @@
</article> </article>
</div> </div>
<% } =%> <% } =%>
<% if (my $first_reply = @$replies[0]) { =%> <% if (my $first_remark = @$remarks[0]) { =%>
<div class="replies"> <div class="remarks">
<% for my $reply (@$replies) { =%> <% for my $remark (@$remarks) { =%>
<article class="reply"> <article class="remark">
<h4 class="date"><%= %$reply{'date'} %></h4> <h4 class="date"><%= %$remark{'date'} %></h4>
<h5 class="author"><%= %$reply{'author'} %></h5> <h5 class="author"><%= %$remark{'author'} %></h5>
<p class="body"><%= %$reply{'body'} %></p> <p class="body"><%= %$remark{'body'} %></p>
</article> </article>
<% } =%> <% } =%>
</div> </div>