From 9062d983b4a1d2a80304b495d0973c95a303caa9 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Mon, 22 Aug 2022 12:09:43 -0400 Subject: [PATCH] Add Remark model --- lib/PostText/Model/Remark.pm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/PostText/Model/Remark.pm diff --git a/lib/PostText/Model/Remark.pm b/lib/PostText/Model/Remark.pm new file mode 100644 index 0000000..92a2019 --- /dev/null +++ b/lib/PostText/Model/Remark.pm @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +package PostText::Model::Remark; + +use Mojo::Base -base, -signatures; + +has 'pg'; + +sub new($class, $pg, $pg_reference) { + bless { + $pg => $pg_reference, + remarks_per_page => 5, + date_format => 'Dy Mon FMDD HH24:MI TZ YYYY' + }, $class +} + +sub get_remarks_by_thread_id($self, $thread_id) { + my $date_format = %$self{'date_format'}; + + $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hashes(); + SELECT remark_id AS id, + TO_CHAR(remark_date, ?) AS date, + remark_author AS author, + remark_body AS body + FROM replies + WHERE thread_id = ? + AND NOT hidden_status + ORDER BY remark_date ASC; + END_SQL +} + +1;