From 8c69bf31c065cceff4ce8f7d34c81293442ab1c2 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Fri, 4 Apr 2025 19:33:23 -0400 Subject: [PATCH] Do migration and add markdown_status to Models --- README.md | 2 +- lib/PostText.pm | 2 +- lib/PostText/Model/Remark.pm | 28 +++++++++++++++++++++------- lib/PostText/Model/Thread.pm | 34 +++++++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f30fa1c..8828004 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ tests locally: ## TODOs -- Stop working on this and start the imageboard +- Do I need `SUM` for `by_id()`? ## AGPL-3.0+ANTIFA compliance diff --git a/lib/PostText.pm b/lib/PostText.pm index 5910662..acfd523 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -91,7 +91,7 @@ sub startup($self) { # Finish configuring some things $self->secrets($self->config->{'secrets'}) || die $@; - $self->pg->migrations->from_dir('migrations')->migrate(15); + $self->pg->migrations->from_dir('migrations')->migrate(16); if (my $threads_per_page = $self->config->{'threads_per_page'}) { $self->thread->per_page($threads_per_page) diff --git a/lib/PostText/Model/Remark.pm b/lib/PostText/Model/Remark.pm index d74fdc2..7f080e1 100644 --- a/lib/PostText/Model/Remark.pm +++ b/lib/PostText/Model/Remark.pm @@ -18,7 +18,8 @@ sub by_page_for($self, $thread_id, $this_page = 1) { SELECT remark_id AS id, TO_CHAR(remark_date, ?) AS date, remark_author AS author, - remark_body AS body + remark_body AS body, + markdown_status AS markdown FROM remarks WHERE thread_id = ? AND NOT hidden_status @@ -27,7 +28,16 @@ sub by_page_for($self, $thread_id, $this_page = 1) { END_SQL } -sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) { +sub create( + $self, + $thread_id, + $author, + $body, + $markdown = 0, + $hidden = 0, + $flagged = 0 + ) +{ my $clean_body = $self->hr->process($body); my @data = ($thread_id, $author, $clean_body, $hidden, $flagged); @@ -37,9 +47,10 @@ sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) { remark_author, remark_body, hidden_status, - flagged_status + flagged_status, + markdown_status ) - VALUES (?, ?, ?, ?, ?); + VALUES (?, ?, ?, ?, ?, ?); END_SQL } @@ -69,7 +80,8 @@ sub last_for($self, $thread_id) { SELECT remark_id AS id, TO_CHAR(remark_date, ?) AS date, remark_author AS author, - remark_body AS body + remark_body AS body, + markdown_status AS markdown FROM remarks WHERE thread_id = ? ORDER BY remark_date @@ -85,7 +97,8 @@ sub by_id($self, $remark_id) { TO_CHAR(remark_date, ?) AS date, remark_author AS author, remark_body AS body, - thread_id + thread_id, + markdown_status AS markdown FROM remarks WHERE remark_id = ? AND NOT hidden_status; @@ -122,7 +135,8 @@ sub feed($self) { $self->pg->db->query(<<~'END_SQL', $date_format)->hashes; SELECT remark_id AS id, TO_CHAR(remark_date, ?) AS date, - remark_body AS body + remark_body AS body, + markdown_status AS markdown FROM remarks WHERE NOT hidden_status GROUP BY remark_id diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 756c1d1..9d05413 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -8,9 +8,25 @@ has per_page => 5; has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM'; -sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) { +sub create( + $self, + $author, + $title, + $body, + $markdown = 0, + $hidden = 0, + $flagged = 0 + ) +{ my $clean_body = $self->hr->process($body); - my @data = ($author, $title, $clean_body, $hidden, $flagged); + my @data = ( + $author, + $title, + $clean_body, + $hidden, + $flagged, + $markdown + ); $self->pg->db->query(<<~'END_SQL', @data)->hash->{'thread_id'}; INSERT INTO threads ( @@ -18,9 +34,10 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) { thread_title, thread_body, hidden_status, - flagged_status + flagged_status, + markdown_status ) - VALUES (?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?) RETURNING thread_id; END_SQL # The indented heredoc got a little confused by this one... @@ -43,7 +60,8 @@ sub by_page($self, $this_page = 1) { THEN 1 ELSE 0 END) AS remark_tally, - t.bump_tally AS bump_tally + t.bump_tally AS bump_tally, + t.markdown_status AS markdown FROM threads AS t LEFT JOIN remarks AS r ON t.thread_id = r.thread_id @@ -87,7 +105,8 @@ sub by_id($self, $thread_id) { t.thread_title AS title, t.thread_body AS body, COUNT(r.*) AS remark_tally, - t.bump_tally AS bump_tally + t.bump_tally AS bump_tally, + t.markdown_status AS markdown FROM threads AS t LEFT JOIN remarks AS r ON t.thread_id = r.thread_id @@ -121,7 +140,8 @@ sub feed($self) { SELECT thread_id AS id, TO_CHAR(thread_date, ?) AS date, thread_title AS title, - thread_body AS body + thread_body AS body, + markdown_status AS markdown FROM threads WHERE NOT hidden_status GROUP BY thread_id