Refactor notification handling in Workers: Centralize notification insertion and frontend updates by replacing direct SQL queries with dedicated functions. This improves code maintainability and reduces redundancy across character creation, events, and transport processing.

This commit is contained in:
Torsten Schulz (local)
2025-12-22 13:58:17 +01:00
parent a82d554494
commit fce7400303
7 changed files with 183 additions and 47 deletions

View File

@@ -13,8 +13,8 @@ use crate::worker::sql::{
QUERY_DELETE_PRODUCTION,
QUERY_INSERT_INVENTORY,
QUERY_INSERT_UPDATE_PRODUCTION_LOG,
QUERY_ADD_OVERPRODUCTION_NOTIFICATION,
};
use crate::worker::insert_notification_conn;
/// Abbildet eine abgeschlossene Produktion aus der Datenbank.
#[derive(Debug, Clone)]
@@ -402,22 +402,13 @@ impl ProduceWorker {
.get()
.map_err(|e| crate::db::DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
conn.prepare(
"add_overproduction_notification",
QUERY_ADD_OVERPRODUCTION_NOTIFICATION,
)?;
// Zusätzlich zur Menge die Branch-ID in der Payload mitschicken, damit
// das Frontend die Überproduktion einem konkreten Branch zuordnen kann.
let notification = format!(
r#"{{"tr":"production.overproduction","value":{},"branch_id":{}}}"#,
remaining_quantity, branch_id
);
conn.execute(
"add_overproduction_notification",
&[&user_id, &notification],
)?;
insert_notification_conn(&mut conn, user_id, &notification, None)?;
Ok(())
}