Batch processor (.trsr charge) now also accessible via web interface
Plus, added `./trsr server` and `./trsr sql` calls. These are essentially execs of morbo and sqlite3 with appropriate arguments.
This commit is contained in:
@@ -97,12 +97,14 @@ sub startup {
|
||||
my $c = shift;
|
||||
return $c->stash('grade') > 1 || undef;
|
||||
});
|
||||
|
||||
$admin->any('/admin')->to('admin#dash');
|
||||
$admin->any( [qw/GET POST/] => '/account/:account' => { account => undef })
|
||||
->to('account#upsert');
|
||||
$admin->any( [qw/GET POST/] => '/:account/in')->to('credit#upsert');
|
||||
$admin->any( [qw/GET POST/] => '/:account/out')->to('debit#upsert');
|
||||
$admin->post('/:account/transfer')->to('account#transfer');
|
||||
$admin->any( [qw/GET POST/] => '/batch-processor' )->to('account#batch_processor');
|
||||
$admin->any( [qw/GET POST PATCH/] => '/credit/:id' )->to('credit#upsert');
|
||||
$admin->any( [qw/GET POST/] => '/credit')->to('credit#upsert');
|
||||
$admin->any( [qw/GET POST PATCH/] => '/debit/*id' )->to('debit#upsert');
|
||||
|
||||
@@ -3,6 +3,7 @@ use strict;
|
||||
package TrsrDB::HTTP::Account;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
use Carp qw(croak);
|
||||
use FindBin qw($Bin);
|
||||
|
||||
sub list {
|
||||
my $self = shift;
|
||||
@@ -79,6 +80,25 @@ sub upsert {
|
||||
return;
|
||||
}
|
||||
|
||||
sub batch_processor {
|
||||
my $self = shift;
|
||||
|
||||
if ( $self->req->method eq 'POST' ) {
|
||||
my $text = $self->req->headers->content_type =~ m{^text/plain\b}
|
||||
? $self->req->body
|
||||
: $self->param("batch")
|
||||
;
|
||||
open my $fh, '<', \$text;
|
||||
require "$Bin/trsr" or die;
|
||||
$self->app->db->storage->txn_do(sub {
|
||||
Commands::act_on_other_db($self->app->db);
|
||||
Commands::charge_account($fh);
|
||||
});
|
||||
$self->redirect_to('home');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub history {
|
||||
my $self = shift;
|
||||
my %query = ( account => $self->stash("account") );
|
||||
|
||||
Reference in New Issue
Block a user