diff --git a/lib/CF/Controller/Posts.pm b/lib/CF/Controller/Posts.pm index e90e791dcc58d9a89ab8c469f07ac9601dbdcf02..1745de58abea45758aea87cdab8b77b4951a54e1 100644 --- a/lib/CF/Controller/Posts.pm +++ b/lib/CF/Controller/Posts.pm @@ -32,12 +32,6 @@ sub create ($c) { my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); - # TODO: vyhodit - $pubsub->json('posts')->notify( posts => { - event => 'created', - payload => $post->view->format(), - }); - $pubsub->json('notify')->notify( notify => { event => 'post_created', payload => $post->view->format(), @@ -81,6 +75,8 @@ sub list ($c) { my ($cond, $attrs) = $c->search_parametrs( $args ); + $cond->{deleted} = undef; + # Vzdy jen k jednemu programovemu bodu - parametr nebo aktualni if ( $args->{program_entry_id} ) { $cond->{program_entry_id} = $args->{program_entry_id}; @@ -192,6 +188,28 @@ sub update ($c) { $c->render(status => 204, text => ''); } +sub delete ($c) { + $c->openapi->valid_input or return; + + my $post = $c->schema->resultset('Post')->find($c->stash->{id}); + return $c->error(404, 'Post not found') if ! $post; + + my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); + my $guard = $c->schema->txn_scope_guard; + + $post->update({ deleted => \'now()', }); + + $pubsub->json('notify')->notify( notify => { + event => 'post_deleted', + payload => { + id => $post->id, + } + }); + + $guard->commit; + $c->render(status => 204, text => ''); +} + sub ranking ($c) { $c->openapi->valid_input or return; my $args = $c->validation->output;