Bump thread after remark; redirect to last remark page after remark; some small tweaks/clean-up

This commit is contained in:
swag 2022-10-01 23:53:44 -04:00
parent 33bcb0255b
commit 898b3d8cd1
4 changed files with 29 additions and 17 deletions

View File

@ -19,7 +19,8 @@ should be YAML or XML or something better suited.
Run it in development mode: Run it in development mode:
morbo -w assets/css/ -w lib/ -w migrations/ -w t/ -w templates/ PostText.pl morbo -w assets/css/ -w lib/ -w migrations/ -w t/ -w templates/ \
script/post_text
Now try requesting http://localhost:3000 Now try requesting http://localhost:3000

View File

@ -33,13 +33,16 @@ sub create($self) {
$thread_id, $thread_id,
$remark_author, $remark_author,
$remark_body $remark_body
); );
$self->session(author => $remark_author); $self->session(author => $remark_author);
return $self->redirect_to( $self->thread->bump($thread_id);
single_thread => {thread_id => $thread_id}
); return $self->redirect_to(single_thread => {
thread_id => $thread_id,
thread_page => $self->remark->last_page_for($thread_id)
});
} }
} }

View File

@ -13,8 +13,8 @@ sub new($class, $pg, $pg_reference) {
} }
sub by_page_for($self, $thread_id, $this_page = 1) { sub by_page_for($self, $thread_id, $this_page = 1) {
my $date_format = %$self{'date_format'}; my $date_format = $self->{'date_format'};
my $row_count = %$self{'remarks_per_page'}; my $row_count = $self->{'remarks_per_page'};
my $offset = ($this_page - 1) * $row_count; my $offset = ($this_page - 1) * $row_count;
my @data = ($date_format, $thread_id, $row_count, $offset); my @data = ($date_format, $thread_id, $row_count, $offset);
@ -40,12 +40,12 @@ sub create($self, $thread_id, $author, $body, $hidden = 0, $flagged = 0) {
$self->pg->db->query(<<~'END_SQL', @data); $self->pg->db->query(<<~'END_SQL', @data);
INSERT INTO remarks ( INSERT INTO remarks (
thread_id, thread_id,
remark_author, remark_author,
remark_body, remark_body,
hidden_status, hidden_status,
flagged_status flagged_status
) )
VALUES (?, ?, ?, ?, ?); VALUES (?, ?, ?, ?, ?);
END_SQL END_SQL
} }
@ -66,7 +66,7 @@ sub last_page_for($self, $thread_id) {
# Add a page for 'remainder' posts # Add a page for 'remainder' posts
$last_page++ if $remark_count % $self->{'remarks_per_page'}; $last_page++ if $remark_count % $self->{'remarks_per_page'};
$last_page; return $last_page;
} }
sub last_for($self, $thread_id) { sub last_for($self, $thread_id) {

View File

@ -29,7 +29,7 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
} }
sub dump_all($self) { sub dump_all($self) {
$self->pg->db->query(<<~'END_SQL', %$self{'date_format'})->hashes $self->pg->db->query(<<~'END_SQL', $self->{'date_format'})->hashes
SELECT thread_id AS id, SELECT thread_id AS id,
TO_CHAR(thread_date, ?) AS date, TO_CHAR(thread_date, ?) AS date,
thread_author AS author, thread_author AS author,
@ -42,7 +42,7 @@ sub dump_all($self) {
} }
sub by_page($self, $this_page = 1) { sub by_page($self, $this_page = 1) {
my $date_format = %$self{'date_format'}; my $date_format = $self->{'date_format'};
my $row_count = $self->{'threads_per_page'}; my $row_count = $self->{'threads_per_page'};
my $offset = ($this_page - 1) * $row_count; my $offset = ($this_page - 1) * $row_count;
@ -87,7 +87,7 @@ sub count($self) {
} }
sub by_id($self, $thread_id) { sub by_id($self, $thread_id) {
my $date_format = %$self{'date_format'}; my $date_format = $self->{'date_format'};
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash; $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash;
SELECT thread_id AS id, SELECT thread_id AS id,
@ -100,4 +100,12 @@ sub by_id($self, $thread_id) {
END_SQL END_SQL
} }
sub bump($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)
UPDATE threads
SET bump_date = NOW()
WHERE thread_id = ?;
END_SQL
}
1; 1;