summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-06-21 20:48:53 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-06-21 20:48:53 +0200
commitda87e97a0b954860e0a53b8a0f475580d44ad73d (patch)
tree3626df8b8792df43fcb0edf266059f70fbb92573 /lib/Travelynx/Model
parentca2226b9238ac2159d0001a071edf33915f062ae (diff)
Add bare-bones support for manual checkins (still bound to a specific backend)
Extension opportunities (maybe, eventually) * provide datetimes of intermediate stops * provide an API for real-time data updates * look up stops that travelynx does not yet know about rather than rejecting them outright
Diffstat (limited to 'lib/Travelynx/Model')
-rw-r--r--lib/Travelynx/Model/InTransit.pm38
-rwxr-xr-xlib/Travelynx/Model/Journeys.pm8
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm
index b67b716..cb8f7c4 100644
--- a/lib/Travelynx/Model/InTransit.pm
+++ b/lib/Travelynx/Model/InTransit.pm
@@ -101,6 +101,7 @@ sub add {
my $journey = $opt{journey};
my $stop = $opt{stop};
my $stopover = $opt{stopover};
+ my $manual = $opt{manual};
my $checkin_station_id = $opt{departure_eva};
my $route = $opt{route};
my $data = $opt{data};
@@ -389,16 +390,49 @@ sub add {
sched_departure => $stopover->scheduled_departure,
real_departure => $stopover->departure,
route => $json->encode( \@route ),
- data => JSON->new->encode(
+ data => $json->encode(
{
rt => $stopover->{is_realtime} ? 1 : 0,
%{ $data // {} }
}
),
- user_data => JSON->new->encode($persistent_data),
+ user_data => $json->encode($persistent_data),
+ backend_id => $backend_id,
+ }
+ );
+ }
+ elsif ($manual) {
+ if ( $manual->{comment} ) {
+ $persistent_data->{comment} = $manual->{comment};
+ }
+ $db->insert(
+ 'in_transit',
+ {
+ user_id => $uid,
+ cancelled => 0,
+ checkin_station_id => $manual->{dep_id},
+ checkout_station_id => $manual->{arr_id},
+ checkin_time => DateTime->now( time_zone => 'Europe/Berlin' ),
+ train_type => $manual->{train_type},
+ train_no => $manual->{train_no} || q{},
+ train_id => 'manual',
+ train_line => $manual->{train_line} || undef,
+ sched_departure => $manual->{sched_departure},
+ real_departure => $manual->{sched_departure},
+ sched_arrival => $manual->{sched_arrival},
+ real_arrival => $manual->{sched_arrival},
+ route => $json->encode( $manual->{route} // [] ),
+ data => $json->encode(
+ {
+ manual => \1,
+ %{ $data // {} }
+ }
+ ),
+ user_data => $json->encode($persistent_data),
backend_id => $backend_id,
}
);
+ return;
}
else {
die('invalid arguments / argument types passed to InTransit->add');
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index 0fb663e..876786a 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -283,8 +283,14 @@ sub add_from_in_transit {
my $db = $opt{db};
my $journey = $opt{journey};
+ if ( $journey->{train_id} eq 'manual' ) {
+ $journey->{edited} = 0x3fff;
+ }
+ else {
+ $journey->{edited} = 0;
+ }
+
delete $journey->{data};
- $journey->{edited} = 0;
$journey->{checkout_time} = DateTime->now( time_zone => 'Europe/Berlin' );
return $db->insert( 'journeys', $journey, { returning => 'id' } )