From 5583b9f608cbff3f483d3f2372b9a09fe93ff7e6 Mon Sep 17 00:00:00 2001 From: swag Date: Thu, 7 Apr 2022 23:04:09 -0400 Subject: [PATCH] Consolidate /view and /spam base paths --- guestbook-ng.pl | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/guestbook-ng.pl b/guestbook-ng.pl index a57d7a9..a2ce91e 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -84,7 +84,7 @@ any [qw{GET POST}], '/sign' => sub ($c) { $c->flash(error => 'This message was flagged as spam') if $spam; - return $c->redirect_to('index'); + return $c->redirect_to('view'); } } @@ -124,13 +124,17 @@ group { }; group { - under '/spam'; + under '/:page', [page => ['spam', 'view']]; get '/:number', [number => qr/[0-9]+/], {number => 1} => sub ($c) { - my $this_page = $c->param('number'); - my $last_page = $c->message->get_last_page('spam'); - my $view_posts = $c->message->get_spam($this_page); my $base_path = $c->url_for(number => undef); + my $this_page = $c->param('number'); + my $last_page = + $base_path eq '/view' ? $c->message->get_last_page() + : $c->message->get_last_page(1); + my $view_posts = + $base_path eq '/view' ? $c->message->get_posts($this_page) + : $c->message->get_spam($this_page); $c->stash( view_posts => $view_posts, @@ -143,26 +147,6 @@ group { }; }; -group { - under '/view'; - - get '/:number', [number => qr/[0-9]+/], {number => 1} => sub ($c) { - my $this_page = $c->param('number'); - my $last_page = $c->message->get_last_page('spam'); - my $view_posts = $c->message->get_spam($this_page); - my $base_path = $c->url_for(number => undef); - - $c->stash( - view_posts => $view_posts, - this_page => $this_page, - last_page => $last_page, - base_path => $base_path - ); - - $c->render(); - }; -}; - # Send it app->secrets(app->config->{'secrets'}) || die $@;