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:
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

View File

@ -33,13 +33,16 @@ sub create($self) {
$thread_id,
$remark_author,
$remark_body
);
);
$self->session(author => $remark_author);
return $self->redirect_to(
single_thread => {thread_id => $thread_id}
);
$self->thread->bump($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) {
my $date_format = %$self{'date_format'};
my $row_count = %$self{'remarks_per_page'};
my $date_format = $self->{'date_format'};
my $row_count = $self->{'remarks_per_page'};
my $offset = ($this_page - 1) * $row_count;
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);
INSERT INTO remarks (
thread_id,
remark_author,
remark_body,
hidden_status,
flagged_status
)
thread_id,
remark_author,
remark_body,
hidden_status,
flagged_status
)
VALUES (?, ?, ?, ?, ?);
END_SQL
}
@ -66,7 +66,7 @@ sub last_page_for($self, $thread_id) {
# Add a page for 'remainder' posts
$last_page++ if $remark_count % $self->{'remarks_per_page'};
$last_page;
return $last_page;
}
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) {
$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,
TO_CHAR(thread_date, ?) AS date,
thread_author AS author,
@ -42,7 +42,7 @@ sub dump_all($self) {
}
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 $offset = ($this_page - 1) * $row_count;
@ -87,7 +87,7 @@ sub count($self) {
}
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;
SELECT thread_id AS id,
@ -100,4 +100,12 @@ sub by_id($self, $thread_id) {
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;