diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index df43bf5..c4ee95e 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -185,6 +185,10 @@ sub startup { $admin_routes->get('/feedback')->to('admin-feedback#index'); $admin_routes->get('/feedback/:id')->to('admin-feedback#read'); + $admin_routes->get('/transactions')->to('admin-transactions#index'); + $admin_routes->get('/transactions/:id')->to('admin-transactions#read'); + $admin_routes->get('/transactions/:id/image')->to('admin-transactions#image'); + # my $user_routes = $r->under('/')->to('root#under'); # $user_routes->get('/home')->to('root#home'); diff --git a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm new file mode 100644 index 0000000..ecb18a0 --- /dev/null +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -0,0 +1,51 @@ +package Pear::LocalLoop::Controller::Admin::Transactions; +use Mojo::Base 'Mojolicious::Controller'; + +has result_set => sub { + my $c = shift; + return $c->schema->resultset('Transaction'); +}; + +sub index { + my $c = shift; + + my $transactions = $c->result_set->search( + undef, { + page => $c->param('page') || 1, + rows => 10, + order_by => { -desc => 'submitted_at' }, + }, + ); + $c->stash( + transactions => $transactions, + ); +} + +sub read { + my $c = shift; + + my $id = $c->param('id'); + + if ( my $transaction = $c->result_set->find($id) ) { + $c->stash( transaction => $transaction ); + } else { + $c->flash( error => 'No transaction found' ); + $c->redirect_to( '/admin/transactions' ); + } +} + +sub image { + my $c = shift; + + my $id = $c->param('id'); + + my $transaction = $c->result_set->find($id); + + if ( $transaction->proof_image ) { + $c->reply->asset($c->get_file_from_uuid($transaction->proof_image)); + } else { + $c->reply->static('image/no_transaction.jpg'); + } +} + +1; diff --git a/public/image/no_transaction.jpg b/public/image/no_transaction.jpg new file mode 100644 index 0000000..8c2e148 Binary files /dev/null and b/public/image/no_transaction.jpg differ diff --git a/templates/admin/organisations/valid_read.html.ep b/templates/admin/organisations/valid_read.html.ep index 5bbe739..e390e5d 100644 --- a/templates/admin/organisations/valid_read.html.ep +++ b/templates/admin/organisations/valid_read.html.ep @@ -71,13 +71,15 @@ % for my $transaction ( $transactions->all ) {