Commit f6d56d31 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add proper journey comment support

parent d08c1ead
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -325,8 +325,8 @@ sub startup {
			};

			if ( $opt{comment} ) {
				$entry->{messages}
				  = JSON->new->encode( [ [ 0, $opt{comment} ] ] );
				$entry->{user_data}
				  = JSON->new->encode( { comment => $opt{comment} } );
			}

			my $journey_id = undef;
@@ -2228,6 +2228,9 @@ sub startup {
					messages        => $entry->{messages},
					route           => $entry->{route},
					edited          => $entry->{edited},
					comment         => $entry->{user_data}
					? $entry->{user_data}{comment}
					: undef,
				};

				if ( $opt{verbose} ) {
+75 −0
Original line number Diff line number Diff line
@@ -705,6 +705,81 @@ my @migrations = (
			}
		);
	},

	# v16 -> v17
	sub {
		my ($db) = @_;
		$db->query(
			qq{
				drop view journeys_str;
				drop view in_transit_str;
				alter table journeys add column user_data jsonb;
				alter table in_transit add column user_data jsonb;
				create view journeys_str as select
					journeys.id as journey_id, user_id,
					train_type, train_line, train_no, train_id,
					extract(epoch from checkin_time) as checkin_ts,
					extract(epoch from sched_departure) as sched_dep_ts,
					extract(epoch from real_departure) as real_dep_ts,
					dep_stations.ds100 as dep_ds100,
					dep_stations.name as dep_name,
					extract(epoch from checkout_time) as checkout_ts,
					extract(epoch from sched_arrival) as sched_arr_ts,
					extract(epoch from real_arrival) as real_arr_ts,
					arr_stations.ds100 as arr_ds100,
					arr_stations.name as arr_name,
					cancelled, edited, route, messages, user_data,
					dep_platform, arr_platform
					from journeys
					join stations as dep_stations on dep_stations.id = checkin_station_id
					join stations as arr_stations on arr_stations.id = checkout_station_id
					;
				create view in_transit_str as select
					user_id,
					train_type, train_line, train_no, train_id,
					extract(epoch from checkin_time) as checkin_ts,
					extract(epoch from sched_departure) as sched_dep_ts,
					extract(epoch from real_departure) as real_dep_ts,
					dep_stations.ds100 as dep_ds100,
					dep_stations.name as dep_name,
					extract(epoch from checkout_time) as checkout_ts,
					extract(epoch from sched_arrival) as sched_arr_ts,
					extract(epoch from real_arrival) as real_arr_ts,
					arr_stations.ds100 as arr_ds100,
					arr_stations.name as arr_name,
					cancelled, route, messages, user_data,
					dep_platform, arr_platform
					from in_transit
					join stations as dep_stations on dep_stations.id = checkin_station_id
					left join stations as arr_stations on arr_stations.id = checkout_station_id
					;
			}
		);
		for my $journey ( $db->select( 'journeys', [ 'id', 'messages' ] )
			->expand->hashes->each )
		{
			if (    $journey->{messages}
				and @{ $journey->{messages} }
				and $journey->{messages}[0][0] == 0 )
			{
				my $comment = $journey->{messages}[0][1];
				$db->update(
					'journeys',
					{
						user_data =>
						  JSON->new->encode( { comment => $comment } ),
						messages => undef
					},
					{ id => $journey->{id} }
				);
			}
		}
		$db->query(
			qq{
				update schema_version set version = 17;
			}
		);
	},
);

sub setup_db {
+3 −1
Original line number Diff line number Diff line
@@ -215,6 +215,7 @@ $t->post_ok(
		arr_station     => 'EG',
		sched_arrival   => '16.10.2018 18:34',
		rt_arrival      => '16.10.2018 18:34',
		comment         => 'Passierschein A38',
	}
);
$t->status_is(302)->header_is( location => '/journey/1' );
@@ -223,7 +224,8 @@ $t->get_ok('/journey/1')->status_is(200)->content_like(qr{M.nster\(Westf\)Hbf})
  ->content_like(qr{Gelsenkirchen Hbf})->content_like(qr{RE 11238})
  ->content_like(qr{Linie 42})->content_like(qr{..:36})
  ->content_like(qr{..:34})->content_like(qr{ca[.] 62 km})
  ->content_like(qr{Luftlinie: 62 km})->content_like(qr{64 km/h});
  ->content_like(qr{Luftlinie: 62 km})->content_like(qr{64 km/h})
  ->content_like(qr{Passierschein A38});

$t->get_ok('/history/2018/10')->status_is(200)->content_like(qr{62 km})
  ->content_like(qr{00:58 Stunden})->content_like(qr{00:00 Stunden})
+2 −4
Original line number Diff line number Diff line
@@ -121,13 +121,11 @@
						% }
					</td>
				</tr>
				% if ($journey->{edited} == 0x3fff) {
				% if ($journey->{comment}) {
					<tr>
						<th scope="row">Kommentar</th>
						<td>
							% for my $message (@{$journey->{messages} // []}) {
								<%= $message->[1] %><br/>
							% }
							<%= $journey->{comment} %>
						</td>
					</tr>
				% }