get_user_status_json_v1: add public flag to hide actionTime

This commit is contained in:
Derf Null 2023-05-21 19:44:43 +02:00
parent 2e10115072
commit dbc5c38968
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA
2 changed files with 24 additions and 21 deletions

View file

@ -836,7 +836,7 @@ sub startup {
return;
}
my $status = $self->get_user_status_json_v1($uid);
my $status = $self->get_user_status_json_v1( uid => $uid );
my $header = {};
my $hook_body = {
reason => $reason,
@ -1694,11 +1694,10 @@ sub startup {
$self->helper(
'get_user_status_json_v1' => sub {
my ( $self, $uid ) = @_;
my ( $self, %opt ) = @_;
my $uid = $opt{uid};
my $status = $self->get_user_status($uid);
# TODO simplify lon/lat (can be returned from get_user_status)
my $ret = {
deprecated => \0,
checkedIn => (
@ -1737,12 +1736,16 @@ sub startup {
no => $status->{train_no},
id => $status->{train_id},
},
actionTime => $status->{timestamp}
? $status->{timestamp}->epoch
: undef,
intermediateStops => [],
};
if ( not $opt{public} ) {
$ret->{actionTime}
= $status->{timestamp}
? $status->{timestamp}->epoch
: undef;
}
for my $stop ( @{ $status->{route_after} // [] } ) {
if ( $status->{arr_name} and $stop->[0] eq $status->{arr_name} )
{

View file

@ -93,7 +93,7 @@ sub get_v1 {
return;
}
if ( $api_action eq 'status' ) {
$self->render( json => $self->get_user_status_json_v1($uid) );
$self->render( json => $self->get_user_status_json_v1( uid => $uid ) );
}
else {
$self->render(
@ -166,7 +166,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Missing or invalid action',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
},
);
return;
@ -190,7 +190,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Missing fromStation or train data',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
},
);
return;
@ -202,7 +202,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Unknown fromStation',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
},
);
return;
@ -214,7 +214,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Unknown toStation',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
},
);
return;
@ -238,7 +238,7 @@ sub travel_v1 {
error =>
'Error requesting departures from fromStation: '
. $status->{errstr},
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
return;
@ -253,7 +253,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Train not found at fromStation',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
return;
@ -285,7 +285,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Checkin/Checkout error: ' . $error,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
@ -294,7 +294,7 @@ sub travel_v1 {
json => {
success => \1,
deprecated => \0,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
@ -308,7 +308,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Missing toStation',
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
},
);
return;
@ -332,7 +332,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => 'Checkout error: ' . $error,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
@ -341,7 +341,7 @@ sub travel_v1 {
json => {
success => \1,
deprecated => \0,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
@ -354,7 +354,7 @@ sub travel_v1 {
success => \0,
deprecated => \0,
error => $error,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
@ -363,7 +363,7 @@ sub travel_v1 {
json => {
success => \1,
deprecated => \0,
status => $self->get_user_status_json_v1($uid)
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}