Created
May 8, 2018 15:09
-
-
Save jjn1056/258bf3c2c3ea95cb98f7123168267165 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Current | |
sub new_transaction($self, $c) : POST At('/transactions/new') { | |
my $form = $c->model('Form::Transaction'); | |
if($form->validated) { | |
if(my $result = $c->model('Blockchain')->submit_transaction(%{$form->fif})) { | |
return $c->view('TransactionAdded', transaction_result=>$result)->http_201; | |
} else { | |
return $c->view('InvalidTransaction')->http_406; | |
} | |
} else { | |
return $c->view('InvalidTransaction', errors=>$form->errors)->http_406; | |
} | |
} | |
## Flat API approach | |
sub new_transaction($self, $c) : POST At('/transactions/new') { | |
my $form = $c->form('Transaction'); | |
if($form->validated) { | |
if(my $result = $c->blockchain->submit_transaction(%{$form->fif})) { | |
return $c->send_json(201, +{transaction_result=>$result}); | |
} else { | |
return $c->send_json(406, +{message=>'Transaction Error!'}); | |
} | |
} else { | |
$c->send_json(400, +{errors=>$form->errors'}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment