From 898b3d8cd1af8dab20b70a47672273b1fa7fe7b0 Mon Sep 17 00:00:00 2001 From: swag Date: Sat, 1 Oct 2022 23:53:44 -0400 Subject: [PATCH] Bump thread after remark; redirect to last remark page after remark; some small tweaks/clean-up --- README.md | 3 ++- lib/PostText/Controller/Remark.pm | 11 +++++++---- lib/PostText/Model/Remark.pm | 18 +++++++++--------- lib/PostText/Model/Thread.pm | 14 +++++++++++--- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4a751dd..fcc8d53 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/PostText/Controller/Remark.pm b/lib/PostText/Controller/Remark.pm index f1931bc..65da5df 100644 --- a/lib/PostText/Controller/Remark.pm +++ b/lib/PostText/Controller/Remark.pm @@ -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) + }); } } diff --git a/lib/PostText/Model/Remark.pm b/lib/PostText/Model/Remark.pm index 5b0f73e..d65c294 100644 --- a/lib/PostText/Model/Remark.pm +++ b/lib/PostText/Model/Remark.pm @@ -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) { diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index d283c30..248ac3d 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -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;