Back-end stuff to get the URL field working
This commit is contained in:
parent
fb8cc6427e
commit
d9b114f9ea
|
@ -63,10 +63,11 @@ get '/' => sub ($c) {
|
|||
any [qw{GET POST}], '/sign' => sub ($c) {
|
||||
if ($c->req->method() eq 'POST' && $c->param('message')) {
|
||||
my $name = $c->param('name') || 'Anonymous';
|
||||
my $url = $c->param('url');
|
||||
my $message = $c->param('message');
|
||||
my $answer = $c->param('answer');
|
||||
|
||||
$c->message->create_post($name, $message) if $answer;
|
||||
$c->message->create_post($name, $message, $url) if $answer;
|
||||
$c->redirect_to('index');
|
||||
}
|
||||
else {
|
||||
|
@ -93,7 +94,7 @@ app->secrets(app->config->{'secrets'}) || die $@;
|
|||
app->message->max_posts(app->config->{'max_posts'})
|
||||
if app->config->{'max_posts'};
|
||||
|
||||
app->pg->migrations->from_dir('migrations')->migrate(3);
|
||||
app->pg->migrations->from_dir('migrations')->migrate(4);
|
||||
|
||||
app->asset->store->paths(['assets']);
|
||||
app->asset->process('swagg.css', 'css/swagg.css');
|
||||
|
|
|
@ -38,11 +38,19 @@ sub get_posts($self, $this_page = undef) {
|
|||
}
|
||||
}
|
||||
|
||||
sub create_post($self, $name, $message) {
|
||||
sub create_post($self, $name, $message, $url = undef) {
|
||||
if ($url) {
|
||||
$self->pg->db->query(<<~'END_SQL', $name, $url, $message)
|
||||
INSERT INTO messages (message_date, visitor_name, homepage_url, message)
|
||||
VALUES (NOW(), ?, ?, ?);
|
||||
END_SQL
|
||||
}
|
||||
else {
|
||||
$self->pg->db->query(<<~'END_SQL', $name, $message)
|
||||
INSERT INTO messages (message_date, visitor_name, message)
|
||||
VALUES (NOW(), ?, ?);
|
||||
END_SQL
|
||||
}
|
||||
}
|
||||
|
||||
sub max_posts($self, $value = undef) {
|
||||
|
|
2
migrations/4/down.sql
Normal file
2
migrations/4/down.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE messages
|
||||
DROP COLUMN homepage_url;
|
2
migrations/4/up.sql
Normal file
2
migrations/4/up.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE messages
|
||||
ADD homepage_url VARCHAR(256);
|
Loading…
Reference in a new issue