Implement get_threads() and send em to /view

This commit is contained in:
swagg boi 2022-08-04 22:46:35 -04:00
parent c66b23b21a
commit 48de91f31b
4 changed files with 32 additions and 5 deletions

View file

@ -9,6 +9,7 @@ use Mojo::Pg;
# Load the local modules too
use lib 'lib';
use PostText::Model::Thread;
#use Data::Dumper; # For your debugging pleasure
# Load Mojo plugins
plugin 'Config';
@ -34,7 +35,11 @@ get '/', sub ($c) { $c->redirect_to('view') };
# View
get '/view', sub ($c) {
$c->render()
my $threads = $c->thread->get_threads();
$c->stash(threads => $threads);
$c->render();
};
# Post

View file

@ -25,6 +25,6 @@ Run the tests locally (against development environment)
## TODOs
1. Moar tests...
1. Retreive threads for View route
1. Pick a date format
1. Validate input
1. **Moar tests!!**

View file

@ -25,4 +25,17 @@ sub create_thread($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
END_SQL
}
sub get_threads($self) {
$self->pg->db->query(<<~'END_SQL')->hashes()
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 NOT hidden_status
ORDER BY thread_date DESC;
END_SQL
}
1;

View file

@ -1,4 +1,13 @@
% layout 'main';
% title 'View Threads';
<h2><%= title %></h2>
<p>Some threads here...</p>
<div class="threads">
<% for my $thread (@$threads) { =%>
<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>