diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 07:12:52 +0200 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-07-27 07:13:13 +0200 | 
| commit | f5091f1081551bb27c4dcf87cf9c514cc53c400f (patch) | |
| tree | ce16fea5510ad1807d8306fcf0298d9710ebbe64 /lib/Travelynx | |
| parent | 1edae95223de4ed49aa09625ae405bb3ce16e957 (diff) | |
Allows journeys to be exported (downloaded) as raw JSON
Closes #279
Diffstat (limited to 'lib/Travelynx')
| -rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 66 | 
1 files changed, 41 insertions, 25 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index a28ae98..a821f3a 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -2121,11 +2121,17 @@ sub journey_details {  	$self->param( journey_id => $journey_id );  	if ( not( $journey_id and $journey_id =~ m{ ^ \d+ $ }x ) ) { -		$self->render( -			'journey', -			status  => 404, -			error   => 'notfound', -			journey => {} +		$self->respond_to( +			json => { +				json   => { error => 'not found' }, +				status => 404 +			}, +			any => { +				template => 'journey', +				status   => 404, +				error    => 'notfound', +				journey  => {} +			}  		);  		return;  	} @@ -2178,29 +2184,39 @@ sub journey_details {  				$delay,           $journey->{rt_arrival}->strftime('%H:%M') );  		} -		$self->render( -			'journey', -			title => sprintf( -				'travelynx: Fahrt %s %s %s am %s', -				$journey->{type}, $journey->{line} // '', -				$journey->{no}, -				$journey->{sched_departure}->strftime('%d.%m.%Y um %H:%M') -			), -			error              => undef, -			journey            => $journey, -			journey_visibility => $visibility, -			with_map           => 1, -			with_share         => $with_share, -			share_text         => $share_text, -			%{$map_data}, +		$self->respond_to( +			json => { json => $journey }, +			any  => { +				template => 'journey', +				title    => sprintf( +					'travelynx: Fahrt %s %s %s am %s', +					$journey->{type}, +					$journey->{line} // '', +					$journey->{no}, +					$journey->{sched_departure}->strftime('%d.%m.%Y um %H:%M') +				), +				error              => undef, +				journey            => $journey, +				journey_visibility => $visibility, +				with_map           => 1, +				with_share         => $with_share, +				share_text         => $share_text, +				%{$map_data}, +			}  		);  	}  	else { -		$self->render( -			'journey', -			status  => 404, -			error   => 'notfound', -			journey => {} +		$self->respond_to( +			json => { +				json   => { error => 'not found' }, +				status => 404 +			}, +			any => { +				template => 'journey', +				status   => 404, +				error    => 'notfound', +				journey  => {} +			}  		);  	}  | 
