Skip to content
Snippets Groups Projects
Verified Commit c3784c10 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Update programu

parent dc432a05
Branches
No related tags found
No related merge requests found
package CF::Controller::Program;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Pg::PubSub;
use feature 'signatures';
no warnings qw{ experimental::signatures };
sub entries {
my $c = shift->openapi->valid_input or return;
......@@ -23,4 +27,36 @@ sub entries {
$c->render(openapi => \@entries );
}
sub update ($c) {
$c->openapi->valid_input or return;
my $entry = $c->schema->resultset('ProgramEntry')->find( $c->stash->{id} );
return $c->error(404, 'Program entry not found') if ! $entry;
my $update = $c->prepare_update_data( $entry, $c->req->json );
my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg);
my $guard = $c->schema->txn_scope_guard;
# muze byt jen jeden aktualni bod programu
if ( $update->{is_live} ) {
$c->schema->resultset('ProgramEntry')->search({})->update(
{ is_live => 'f' }
);
}
$entry->update( $update );
$pubsub->json('notify')->notify( notify => {
event => 'program_entry_changed',
payload => {
id => $entry->id,
%{ $update },
}
});
$guard->commit;
$c->render(status => 204, text => '');
}
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment