Fixes
This commit is contained in:
+5
-4
@@ -3,6 +3,7 @@ use strict;
|
||||
use Dancer2;
|
||||
use Dancer2::Plugin::Database;
|
||||
use Data::Dumper;
|
||||
use JSON ();
|
||||
use SQL::SplitStatement;
|
||||
use HTTP::Lite;
|
||||
|
||||
@@ -164,8 +165,8 @@ post '/api/v1/task/:task/complete' => sub {
|
||||
# Accept both JSON body and form-encoded data for assign_key/results.
|
||||
my ($assign_key, $results);
|
||||
my $ct = request_header('Content-Type') || '';
|
||||
if ($ct eq 'application/json') {
|
||||
my $body = decode_json(request->body());
|
||||
if ($ct =~ m{application/json}i) {
|
||||
my $body = JSON::decode_json(request->body());
|
||||
$assign_key = $body->{assign_key};
|
||||
$results = $body->{results};
|
||||
} else {
|
||||
@@ -195,7 +196,7 @@ post '/api/v1/task/:task/complete' => sub {
|
||||
}
|
||||
|
||||
# Update the task as completed (store results as JSON text for MariaDB)
|
||||
my $results_json = defined $results ? encode_json($results) : 'null';
|
||||
my $results_json = defined $results ? JSON::encode_json($results) : 'null';
|
||||
my $update_sth = database->prepare("UPDATE tasks SET status='COMPLETED', results=?, updated_at=NOW() WHERE id=?");
|
||||
$update_sth->execute($results_json, $task_id);
|
||||
if($update_sth->rows == 0) {
|
||||
@@ -245,4 +246,4 @@ sub max {
|
||||
|
||||
sub min {
|
||||
return (sort { $a <=> $b } @_)[0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user