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

Generovane announcementy

parent a2c55a44
No related branches found
No related tags found
No related merge requests found
Pipeline #1940 passed
...@@ -5,6 +5,13 @@ use Mojo::Pg::PubSub; ...@@ -5,6 +5,13 @@ use Mojo::Pg::PubSub;
use feature 'signatures'; use feature 'signatures';
no warnings qw{ experimental::signatures }; no warnings qw{ experimental::signatures };
# TODO: do modelu
use constant STATUS_ANNOUNCEMENTS => {
1 => 1, # prijatelny n.p.
2 => 2, # schvaleny n.p.
3 => 0, # zamitnuty n.p.
};
sub create ($c) { sub create ($c) {
$c->openapi->valid_input or return; $c->openapi->valid_input or return;
...@@ -165,6 +172,33 @@ sub update ($c) { ...@@ -165,6 +172,33 @@ sub update ($c) {
my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg); my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg);
my $guard = $c->schema->txn_scope_guard; my $guard = $c->schema->txn_scope_guard;
if ( $update->{state} && $post->state != $update->{state} ) {
my $announcement_type = STATUS_ANNOUNCEMENTS->{ $args->{state} };
#TODO: do modelu
my $msg = $c->schema->resultset('Announcement')->from_template(
$announcement_type,
$post->user->name,
$post->content,
);
my $announcement = $c->schema->resultset('Announcement')->create({
user_id => $c->user->{id},
type => $announcement_type,
content => $msg,
});
# potrebujeme kvuli datumu
$announcement = $c->schema->resultset('Announcement')->find({
id => $announcement->id
});
$pubsub->json('notify')->notify( notify => {
event => 'announcement_created',
payload => $announcement->format(),
});
}
$post->add_to_history({ $post->add_to_history({
user_id => $c->user->{id}, user_id => $c->user->{id},
datetime => $post->changed // $post->datetime, datetime => $post->changed // $post->datetime,
......
...@@ -32,7 +32,27 @@ sub ban ($c){ ...@@ -32,7 +32,27 @@ sub ban ($c){
my $guard = $c->schema->txn_scope_guard; my $guard = $c->schema->txn_scope_guard;
$user->update({ banned_until => \"now()+'8 hour'", }); $user->update({ banned_until => \"now()+'8 hour'", });
#TODO: ANN
#TODO: do modelu
my $msg = $c->schema->resultset('Announcement')->from_template(
5, $user->name,
);
my $announcement = $c->schema->resultset('Announcement')->create({
user_id => $c->user->{id},
type => 5,
content => $msg,
});
# potrebujeme kvuli datumu
$announcement = $c->schema->resultset('Announcement')->find({
id => $announcement->id,
});
$pubsub->json('notify')->notify( notify => {
event => 'announcement_created',
payload => $announcement->format(),
});
$pubsub->json('notify')->notify( notify => { $pubsub->json('notify')->notify( notify => {
event => 'user_banned', event => 'user_banned',
......
...@@ -36,7 +36,7 @@ __PACKAGE__->set_primary_key('id'); ...@@ -36,7 +36,7 @@ __PACKAGE__->set_primary_key('id');
__PACKAGE__->has_one( view => 'CF::Schema::Result::Post_view', 'id'); __PACKAGE__->has_one( view => 'CF::Schema::Result::Post_view', 'id');
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
user => 'Zircon::Schema::Result::User', user => 'CF::Schema::Result::User',
{ {
'foreign.id' => 'self.user_id', 'foreign.id' => 'self.user_id',
}, },
......
...@@ -2,6 +2,9 @@ package CF::Schema::ResultSet::Announcement; ...@@ -2,6 +2,9 @@ package CF::Schema::ResultSet::Announcement;
use strict; use strict;
use warnings; use warnings;
use utf8;
use feature 'signatures';
no warnings qw{ experimental::signatures };
use base 'DBIx::Class::ResultSet'; use base 'DBIx::Class::ResultSet';
...@@ -13,4 +16,21 @@ use constant PROTECTED_FIELDS => [qw( ...@@ -13,4 +16,21 @@ use constant PROTECTED_FIELDS => [qw(
type type
)]; )];
use constant TEMPLATE => {
0 => 'Předsedající prohlásil návrh postupu předložený **%s** za nepřijatelný ' .
'a dál k němu nepřihlíží // **§4 (2) JdŘ CF**',
1 => 'Byl schválen návrh postupu, předložený **%s** ' .
'v následujícím znění: "*%s*"',
2 => 'Předsedající zaznamenal přijatelný návrh postupu, předložený **%s** ' .
'v následujícím znění: "*%s*". ' .
'O návrhu postupu se hlasuje bezodkladně // **§10 (2) JdŘ CF**',
5 => 'Předsedající, pořádkovým opatřením, vykázal z jednání **%s** // **§2 (1) JdŘ CF**',
};
sub from_template ( $class, $id, @args ) {
my $template = TEMPLATE->{$id} // return '';
return sprintf($template, @args);
}
1; 1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment