diff --git a/src/model/event.rs b/src/model/event.rs index e4c2dbc..3581810 100644 --- a/src/model/event.rs +++ b/src/model/event.rs @@ -8,7 +8,14 @@ use ics::{ use serde::Serialize; use sqlx::{FromRow, Row, SqlitePool}; -use super::{notification::Notification, tripdetails::TripDetails, triptype::TripType, user::User}; +use super::{ + notification::Notification, + role::Role, + trip, + tripdetails::{self, TripDetails}, + triptype::TripType, + user::User, +}; #[derive(Serialize, Clone, FromRow, Debug, PartialEq)] pub struct Event { @@ -213,12 +220,35 @@ WHERE trip_details.id=? .ok() } + async fn advertise(db: &SqlitePool, day: &str, planned_starting_time: &str, name: &str) { + let donau = Role::find_by_name(db, "Donau Linz").await.unwrap(); + Notification::create_for_role( + db, + &donau, + &format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", day, planned_starting_time, name), + "Neues Event", + Some(&format!("/planned#{day}")), + None, + ) + .await; + } + pub async fn create( db: &SqlitePool, name: &str, planned_amount_cox: i32, trip_details: &TripDetails, ) { + if trip_details.always_show { + Self::advertise( + db, + &trip_details.day, + &trip_details.planned_starting_time, + name, + ) + .await; + } + sqlx::query!( "INSERT INTO planned_event(name, planned_amount_cox, trip_details_id) VALUES(?, ?, ?)", name, @@ -258,6 +288,16 @@ WHERE trip_details.id=? .await .unwrap(); //Okay, as planned_event can only be created with proper DB backing + if !tripdetails.always_show && update.always_show { + Self::advertise( + db, + &tripdetails.day, + &tripdetails.planned_starting_time, + update.name, + ) + .await; + } + if update.max_people == 0 && !was_already_cancelled { let coxes = Registration::all_cox(db, self.id).await; for user in coxes { diff --git a/templates/planned.html.tera b/templates/planned.html.tera index 0dfab7c..0cccb5e 100644 --- a/templates/planned.html.tera +++ b/templates/planned.html.tera @@ -67,7 +67,7 @@ {% endif %} {% endfor %} {% endif %} -