summaryrefslogtreecommitdiff
path: root/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-03-03 22:35:20 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-03-03 22:35:20 +0100
commit40fe8db0c4dd2eb1208cdc6bdfb2868c84def489 (patch)
tree22c87a1be18acc011577c66b949b1a36c962e44a /index.pl
parent41076aafd5f3590490b64816116d7803d4744ff9 (diff)
Add account info and data export
Diffstat (limited to 'index.pl')
-rwxr-xr-xindex.pl54
1 files changed, 54 insertions, 0 deletions
diff --git a/index.pl b/index.pl
index 3f070ff..71ecd92 100755
--- a/index.pl
+++ b/index.pl
@@ -34,6 +34,8 @@ my %action_type = (
undo => 3,
);
+my @action_types = (qw(checkin checkout undo));
+
app->plugin(
authentication => {
autoload_user => 1,
@@ -754,6 +756,58 @@ post '/action' => sub {
}
};
+get '/a/account' => sub {
+ my ($self) = @_;
+
+ $self->render('account');
+};
+
+get '/a/export.json' => sub {
+ my ($self) = @_;
+ my $uid = $self->get_user_id;
+ my $query = $self->app->get_all_actions_query;
+
+ $query->execute($uid);
+
+ my @entries;
+
+ while ( my @row = $query->fetchrow_array ) {
+ my (
+ $action, $raw_ts, $ds100, $name,
+ $train_type, $train_line, $train_no, $train_id,
+ $raw_sched_ts, $raw_real_ts, $raw_route, $raw_messages
+ ) = @row;
+
+ $name = decode( 'UTF-8', $name );
+ $raw_route = decode( 'UTF-8', $raw_route );
+ $raw_messages = decode( 'UTF-8', $raw_messages );
+ push(
+ @entries,
+ {
+ action => $action_types[ $action - 1 ],
+ action_ts => $raw_ts,
+ station_ds100 => $ds100,
+ station_name => $name,
+ train_type => $train_type,
+ train_line => $train_line,
+ train_no => $train_no,
+ train_id => $train_id,
+ scheduled_ts => $raw_sched_ts,
+ realtime_ts => $raw_real_ts,
+ messages => $raw_messages
+ ? [ map { [ split(qr{:}) ] } split( qr{[|]}, $raw_messages ) ]
+ : undef,
+ route => $raw_route ? [ split( qr{[|]}, $raw_route ) ]
+ : undef,
+ }
+ );
+ }
+
+ $self->render(
+ json => [@entries],
+ );
+};
+
get '/a/history' => sub {
my ($self) = @_;