notification (#282)

Reviewed-on: Ruderverein-Donau-Linz/rowt#282
This commit is contained in:
2024-03-20 16:19:12 +01:00
parent 68a1153885
commit 9d14dae4a7
12 changed files with 274 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
use sqlx::SqlitePool;
use super::{tripdetails::TripDetails, user::User};
use super::{notification::Notification, trip::Trip, tripdetails::TripDetails, user::User};
use crate::model::tripdetails::{Action, CoxAtTrip::Yes};
pub struct UserTrip {}
@@ -27,6 +27,7 @@ impl UserTrip {
//TODO: Check if user sees the event (otherwise she could forge trip_details_id)
let is_cox = trip_details.user_is_cox(db, user).await;
let mut name_newly_registered_person = String::new();
if user_note.is_none() {
if let Yes(action) = is_cox {
match action {
@@ -47,6 +48,8 @@ impl UserTrip {
.execute(db)
.await
.unwrap();
name_newly_registered_person = user.name.clone();
} else {
if !trip_details.user_allowed_to_change(db, user).await {
return Err(UserTripError::NotAllowedToAddGuest);
@@ -59,6 +62,23 @@ impl UserTrip {
.execute(db)
.await
.unwrap();
name_newly_registered_person = user_note.unwrap();
}
if let Some(trip) = Trip::find_by_trip_details(db, trip_details.id).await {
let cox = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
Notification::create(
db,
&cox,
&format!(
"{} hat sich für deine Ausfahrt am {} registriert",
name_newly_registered_person, trip.day
),
"Registrierung bei Ausfahrt",
None,
)
.await;
}
Ok(())