summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/work.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-05-26 17:28:21 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-05-26 17:28:21 +0200
commit7fe95532c1bc559a9ad2c4b96ec37bd0e30f8598 (patch)
treec78cb5abf2833c107ac018ac98886e619231b450 /lib/Travelynx/Command/work.pm
parent45a4089431002ee01b11880d463dd3513b0657ca (diff)
Use JSON for messages and route storage, prepare for extended route data
Diffstat (limited to 'lib/Travelynx/Command/work.pm')
-rw-r--r--lib/Travelynx/Command/work.pm34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index b24e4ad..46f2213 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -2,6 +2,7 @@ package Travelynx::Command::work;
use Mojo::Base 'Mojolicious::Command';
use DateTime;
+use JSON;
use List::Util qw(first);
has description =>
@@ -13,6 +14,7 @@ sub run {
my ($self) = @_;
my $now = DateTime->now( time_zone => 'Europe/Berlin' );
+ my $json = JSON->new;
my $db = $self->app->pg->db;
@@ -47,14 +49,14 @@ sub run {
{
dep_platform => $train->platform,
real_departure => $train->departure,
- route => join( '|', $train->route ),
- messages => join(
- '|',
- map {
- ( $_->[0] ? $_->[0]->epoch : q{} ) . ':'
- . $_->[1]
- } $train->messages
- )
+ route =>
+ $json->encode( [ map { [$_] } $train->route ] ),
+ messages => $json->encode(
+ [
+ map { [ $_->[0]->epoch, $_->[1] ] }
+ $train->messages
+ ]
+ ),
},
{ user_id => $uid }
);
@@ -99,14 +101,14 @@ sub run {
arr_platform => $train->platform,
sched_arrival => $train->sched_arrival,
real_arrival => $train->arrival,
- route => join( '|', $train->route ),
- messages => join(
- '|',
- map {
- ( $_->[0] ? $_->[0]->epoch : q{} ) . ':'
- . $_->[1]
- } $train->messages
- )
+ route =>
+ $json->encode( [ map { [$_] } $train->route ] ),
+ messages => $json->encode(
+ [
+ map { [ $_->[0]->epoch, $_->[1] ] }
+ $train->messages
+ ]
+ ),
},
{ user_id => $uid }
);