Implement Remark model
This commit is contained in:
parent
403b0cea26
commit
7b74dbe787
12
PostText.pl
12
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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -11,13 +11,13 @@
|
|||
</article>
|
||||
</div>
|
||||
<% } =%>
|
||||
<% if (my $first_reply = @$replies[0]) { =%>
|
||||
<div class="replies">
|
||||
<% for my $reply (@$replies) { =%>
|
||||
<article class="reply">
|
||||
<h4 class="date"><%= %$reply{'date'} %></h4>
|
||||
<h5 class="author"><%= %$reply{'author'} %></h5>
|
||||
<p class="body"><%= %$reply{'body'} %></p>
|
||||
<% if (my $first_remark = @$remarks[0]) { =%>
|
||||
<div class="remarks">
|
||||
<% for my $remark (@$remarks) { =%>
|
||||
<article class="remark">
|
||||
<h4 class="date"><%= %$remark{'date'} %></h4>
|
||||
<h5 class="author"><%= %$remark{'author'} %></h5>
|
||||
<p class="body"><%= %$remark{'body'} %></p>
|
||||
</article>
|
||||
<% } =%>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue