This commit is contained in:
Ryan Shpeherd
2026-09-15 13:59:41 -04:00
parent 75f38ec7ed
commit 8f2834775b
3 changed files with 64 additions and 24 deletions
+5 -4
View File
@@ -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];
}
}