All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m45s
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use crate::db::{ConnectionPool, DbConnection, DbError};
|
|
use crate::message_broker::MessageBroker;
|
|
use crate::worker::sql::QUERY_INSERT_NOTIFICATION;
|
|
|
|
/// Schreibt eine Notification in `falukant_log.notification`.
|
|
///
|
|
/// - `tr` ist ein (i.d.R. JSON-)String, den das Frontend parst.
|
|
/// - `character_id` ist optional (NULL).
|
|
pub fn insert_notification(
|
|
pool: &ConnectionPool,
|
|
user_id: i32,
|
|
tr: &str,
|
|
character_id: Option<i32>,
|
|
) -> Result<(), DbError> {
|
|
let mut conn = pool
|
|
.get()
|
|
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
|
|
|
insert_notification_conn(&mut conn, user_id, tr, character_id)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Variante für bestehende DB-Verbindungen (spart Connect/Prepare in Loops).
|
|
pub fn insert_notification_conn(
|
|
conn: &mut DbConnection,
|
|
user_id: i32,
|
|
tr: &str,
|
|
_character_id: Option<i32>,
|
|
) -> Result<(), DbError> {
|
|
conn.prepare("insert_notification_full", QUERY_INSERT_NOTIFICATION)?;
|
|
conn.execute(
|
|
"insert_notification_full",
|
|
&[&user_id, &tr],
|
|
)?;
|
|
Ok(())
|
|
}
|
|
|
|
/// Informiert das Frontend, dass sich der Status geändert hat (z.B. Branches neu laden).
|
|
pub fn publish_update_status(broker: &MessageBroker, user_id: i32) {
|
|
broker.publish(format!(
|
|
r#"{{"event":"falukantUpdateStatus","user_id":{}}}"#,
|
|
user_id
|
|
));
|
|
}
|
|
|