Created
February 4, 2020 20:54
-
-
Save preaction/8a9e2cf56e13ff40d3df9fe9e4999bb6 to your computer and use it in GitHub Desktop.
Extend Yancy controller to add a modified by field
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
package MyApp::Controller::ModifiedBy; | |
use Mojo::Base 'Yancy::Controller::Yancy'; | |
sub _add_modified_by { | |
my ( $c ) = @_; | |
$c->req->param( modified_by => $c->current_uid ); | |
if ( my $item = $c->req->json ) { | |
$item->{ modified_by } = $c->current_uid; | |
} | |
} | |
sub create { | |
my ( $c ) = @_; | |
_add_modified_by( $c ); | |
return $c->SUPER::create; | |
} | |
sub set { | |
my ( $c ) = @_; | |
_add_modified_by( $c ); | |
return $c->SUPER::set; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment