diff options
Diffstat (limited to 'lib/Travelynx/Controller')
-rwxr-xr-x | lib/Travelynx/Controller/Api.pm | 12 | ||||
-rw-r--r-- | lib/Travelynx/Controller/Passengerrights.pm | 13 | ||||
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 109 |
3 files changed, 92 insertions, 42 deletions
diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm index 8af57be..6ffd310 100755 --- a/lib/Travelynx/Controller/Api.pm +++ b/lib/Travelynx/Controller/Api.pm @@ -492,18 +492,18 @@ sub import_v1 { my $tx = $db->begin; $opt{db} = $db; - my ( $journey_id, $error ) = $self->add_journey(%opt); + my ( $journey_id, $error ) = $self->journeys->add(%opt); my $journey; if ( not $error ) { - $journey = $self->get_journey( + $journey = $self->journeys->get_single( uid => $uid, db => $db, journey_id => $journey_id, verbose => 1 ); $error - = $self->journey_sanity_check( $journey, $payload->{lax} ? 1 : 0 ); + = $self->journeys->sanity_check( $journey, $payload->{lax} ? 1 : 0 ); } if ($error) { @@ -526,7 +526,11 @@ sub import_v1 { ); } else { - $self->invalidate_stats_cache( $opt{rt_departure}, $db, $uid ); + $self->journeys->invalidate_stats_cache( + ts => $opt{rt_departure}, + db => $db, + uid => $uid + ); $tx->commit; $self->render( json => { diff --git a/lib/Travelynx/Controller/Passengerrights.pm b/lib/Travelynx/Controller/Passengerrights.pm index 7d9a00b..dc73f37 100644 --- a/lib/Travelynx/Controller/Passengerrights.pm +++ b/lib/Travelynx/Controller/Passengerrights.pm @@ -50,7 +50,8 @@ sub mark_if_missed_connection { sub mark_substitute_connection { my ( $self, $journey ) = @_; - my @substitute_candidates = reverse $self->get_user_travels( + my @substitute_candidates = reverse $self->journeys->get( + uid => $self->current_user->{id}, after => $journey->{sched_departure}->clone->subtract( hours => 1 ), before => $journey->{sched_departure}->clone->add( hours => 12 ), with_datetime => 1, @@ -87,7 +88,8 @@ sub list_candidates { my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $range_start = $now->clone->subtract( months => 6 ); - my @journeys = $self->get_user_travels( + my @journeys = $self->journeys->get( + uid => $self->current_user->{id}, after => $range_start, before => $now, with_datetime => 1, @@ -112,7 +114,8 @@ sub list_candidates { @journeys = grep { $_->{delay} >= 60 or $_->{connection_missed} } @journeys; - my @cancelled = $self->get_user_travels( + my @cancelled = $self->journeys->get( + uid => $self->current_user->{id}, after => $range_start, before => $now, cancelled => 1, @@ -163,7 +166,7 @@ sub generate { return; } - my $journey = $self->get_journey( + my $journey = $self->journeys->get_single( uid => $uid, journey_id => $journey_id, verbose => 1, @@ -187,7 +190,7 @@ sub generate { $self->mark_substitute_connection($journey); } elsif ( $journey->{delay} < 120 ) { - my @connections = $self->get_user_travels( + my @connections = $self->journey->get( uid => $uid, after => $journey->{rt_arrival}, before => $journey->{rt_arrival}->clone->add( hours => 2 ), diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index e33009f..59bad45 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -60,14 +60,14 @@ sub user_status { ) { for my $candidate ( - $self->get_user_travels( + $self->journeys->get( uid => $user->{id}, limit => 10, ) ) { if ( $candidate->{sched_dep_ts} eq $ts ) { - $journey = $self->get_journey( + $journey = $self->journeys->get_single( uid => $user->{id}, journey_id => $candidate->{id}, verbose => 1, @@ -389,8 +389,12 @@ sub log_action { } } elsif ( $params->{action} eq 'delete' ) { - my $error = $self->delete_journey( $params->{id}, $params->{checkin}, - $params->{checkout} ); + my $error = $self->journeys->delete( + uid => $self->current_user->{id}, + id => $params->{id}, + checkin => $params->{checkin}, + checkout => $params->{checkout} + ); if ($error) { $self->render( json => { @@ -474,7 +478,8 @@ sub redirect_to_station { sub cancelled { my ($self) = @_; - my @journeys = $self->get_user_travels( + my @journeys = $self->journeys->get( + uid => $self->current_user->{id}, cancelled => 1, with_datetime => 1 ); @@ -523,7 +528,8 @@ sub commute { ); my $interval_end = $interval_start->clone->add( years => 1 ); - my @journeys = $self->get_user_travels( + my @journeys = $self->journeys->get( + uid => $self->current_user->{id}, after => $interval_start, before => $interval_end, with_datetime => 1, @@ -616,7 +622,10 @@ sub map_history { my $route_type = $self->param('route_type'); my $with_polyline = $route_type eq 'beeline' ? 0 : 1; - my @journeys = $self->get_user_travels( with_polyline => $with_polyline ); + my @journeys = $self->journeys->get( + uid => $self->current_user->{id}, + with_polyline => $with_polyline + ); if ( not @journeys ) { $self->render( @@ -647,7 +656,8 @@ sub map_history { sub json_history { my ($self) = @_; - $self->render( json => [ $self->get_user_travels ] ); + $self->render( + json => [ $self->journeys->get( uid => $self->current_user->{id} ) ] ); } sub csv_history { @@ -669,7 +679,13 @@ sub csv_history { ); $buf .= $csv->string; - for my $journey ( $self->get_user_travels( with_datetime => 1 ) ) { + for my $journey ( + $self->journeys->get( + uid => $self->current_user->{id}, + with_datetime => 1 + ) + ) + { if ( $csv->combine( $journey->{type}, @@ -708,7 +724,10 @@ sub yearly_history { # -> Limit time range to avoid accidental DoS. if ( not( $year =~ m{ ^ [0-9]{4} $ }x and $year > 1990 and $year < 2100 ) ) { - @journeys = $self->get_user_travels( with_datetime => 1 ); + @journeys = $self->journeys->get( + uid => $self->current_user->{id}, + with_datetime => 1 + ); } else { my $interval_start = DateTime->new( @@ -721,7 +740,8 @@ sub yearly_history { second => 0, ); my $interval_end = $interval_start->clone->add( years => 1 ); - @journeys = $self->get_user_travels( + @journeys = $self->journeys->get( + uid => $self->current_user->{id}, after => $interval_start, before => $interval_end, with_datetime => 1 @@ -766,7 +786,10 @@ sub monthly_history { and $month < 13 ) ) { - @journeys = $self->get_user_travels( with_datetime => 1 ); + @journeys = $self->journeys->get( + uid => $self->current_user->{id}, + with_datetime => 1 + ); } else { my $interval_start = DateTime->new( @@ -779,7 +802,8 @@ sub monthly_history { second => 0, ); my $interval_end = $interval_start->clone->add( months => 1 ); - @journeys = $self->get_user_travels( + @journeys = $self->journeys->get( + uid => $self->current_user->{id}, after => $interval_start, before => $interval_end, with_datetime => 1 @@ -827,7 +851,7 @@ sub journey_details { return; } - my $journey = $self->get_journey( + my $journey = $self->journeys->get_single( uid => $uid, journey_id => $journey_id, verbose => 1, @@ -919,7 +943,7 @@ sub edit_journey { return; } - my $journey = $self->get_journey( + my $journey = $self->journeys->get_single( uid => $uid, journey_id => $journey_id, verbose => 1, @@ -952,8 +976,12 @@ sub edit_journey { { my $datetime = $parser->parse_datetime( $self->param($key) ); if ( $datetime and $datetime->epoch ne $journey->{$key}->epoch ) { - $error = $self->update_journey_part( $db, $journey->{id}, - $key, $datetime ); + $error = $self->journeys->update( + uid => $uid, + db => $db, + id => $journey->{id}, + $key => $datetime + ); if ($error) { last; } @@ -963,8 +991,12 @@ sub edit_journey { if ( defined $self->param($key) and $self->param($key) ne $journey->{$key} ) { - $error = $self->update_journey_part( $db, $journey->{id}, $key, - $self->param($key) ); + $error = $self->journeys->update( + uid => $uid, + db => $db, + id => $journey->{id}, + $key => $self->param($key) + ); if ($error) { last; } @@ -977,8 +1009,12 @@ sub edit_journey { or $journey->{user_data}{$key} ne $self->param($key) ) ) { - $error = $self->update_journey_part( $db, $journey->{id}, $key, - $self->param($key) ); + $error = $self->journeys->update( + uid => $uid, + db => $db, + id => $journey->{id}, + $key => $self->param($key) + ); if ($error) { last; } @@ -989,30 +1025,36 @@ sub edit_journey { my @route_new = split( qr{\r?\n\r?}, $self->param('route') ); @route_new = grep { $_ ne '' } @route_new; if ( join( '|', @route_old ) ne join( '|', @route_new ) ) { - $error - = $self->update_journey_part( $db, $journey->{id}, 'route', - [@route_new] ); + $error = $self->journeys->update( + uid => $uid, + db => $db, + id => $journey->{id}, + route => [@route_new] + ); } } { my $cancelled_old = $journey->{cancelled} // 0; my $cancelled_new = $self->param('cancelled') // 0; if ( $cancelled_old != $cancelled_new ) { - $error - = $self->update_journey_part( $db, $journey->{id}, - 'cancelled', $cancelled_new ); + $error = $self->journeys->update( + uid => $uid, + db => $db, + id => $journey->{id}, + cancelled => $cancelled_new + ); } } if ( not $error ) { - $journey = $self->get_journey( + $journey = $self->journeys->get_single( uid => $uid, db => $db, journey_id => $journey_id, verbose => 1, with_datetime => 1, ); - $error = $self->journey_sanity_check($journey); + $error = $self->journeys->sanity_check($journey); } if ( not $error ) { $tx->commit; @@ -1108,18 +1150,19 @@ sub add_journey_form { my $db = $self->pg->db; my $tx = $db->begin; - $opt{db} = $db; + $opt{db} = $db; + $opt{uid} = $self->current_user->{id}; - my ( $journey_id, $error ) = $self->add_journey(%opt); + my ( $journey_id, $error ) = $self->journeys->add(%opt); if ( not $error ) { - my $journey = $self->get_journey( + my $journey = $self->journeys->get_single( uid => $self->current_user->{id}, db => $db, journey_id => $journey_id, verbose => 1 ); - $error = $self->journey_sanity_check($journey); + $error = $self->journeys->sanity_check($journey); } if ($error) { |