This commit is contained in:
Dimitrios Kouros
2026-08-15 06:23:48 +03:00
parent e0848d607d
commit 10ab25bd9d
3 changed files with 26 additions and 12 deletions
+12 -4
View File
@@ -73,7 +73,10 @@ impl Db {
} }
/// Retrieves the FCM token for a given device name (e.g. "Pixel 10"). /// Retrieves the FCM token for a given device name (e.g. "Pixel 10").
pub async fn get_token_by_device(&self, device_name: &str) -> Result<Option<String>, mysql_async::Error> { pub async fn get_token_by_device(
&self,
device_name: &str,
) -> Result<Option<String>, mysql_async::Error> {
let mut conn = self.pool.get_conn().await?; let mut conn = self.pool.get_conn().await?;
let token: Option<String> = conn let token: Option<String> = conn
.exec_first( .exec_first(
@@ -88,7 +91,10 @@ impl Db {
} }
/// Retrieves full device details by device name. /// Retrieves full device details by device name.
pub async fn get_device_by_name(&self, device_name: &str) -> Result<Option<Device>, mysql_async::Error> { pub async fn get_device_by_name(
&self,
device_name: &str,
) -> Result<Option<Device>, mysql_async::Error> {
let mut conn = self.pool.get_conn().await?; let mut conn = self.pool.get_conn().await?;
let row: Option<(i32, Option<String>, Option<String>, Option<i8>, Option<i32>, Option<i32>)> = conn let row: Option<(i32, Option<String>, Option<String>, Option<i8>, Option<i32>, Option<i32>)> = conn
.exec_first( .exec_first(
@@ -99,14 +105,16 @@ impl Db {
) )
.await?; .await?;
Ok(row.map(|(idtoken, device, token, active, pausefrom, pauseto)| Device { Ok(row.map(
|(idtoken, device, token, active, pausefrom, pauseto)| Device {
idtoken, idtoken,
device, device,
token, token,
active, active,
pausefrom, pausefrom,
pauseto, pauseto,
})) },
))
} }
/// Retrieves all devices from the `device` table. /// Retrieves all devices from the `device` table.
+4 -1
View File
@@ -50,7 +50,10 @@ impl EmailService {
let email = Message::builder() let email = Message::builder()
.from(self.email_address.parse()?) .from(self.email_address.parse()?)
.to(self.recipient.parse()?) .to(self.recipient.parse()?)
.subject(format!("[ALERT] FCM Notification Failed for {}", device_name)) .subject(format!(
"[ALERT] FCM Notification Failed for {}",
device_name
))
.header(ContentType::TEXT_PLAIN) .header(ContentType::TEXT_PLAIN)
.body(format!( .body(format!(
"FCM notification delivery failed.\n\nDevice: {}\nError: {}\n", "FCM notification delivery failed.\n\nDevice: {}\nError: {}\n",
+4 -1
View File
@@ -46,7 +46,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Err(err) = service.send_notification(message).await { if let Err(err) = service.send_notification(message).await {
eprintln!("FCM notification failed: {}", err); eprintln!("FCM notification failed: {}", err);
if let Some(es) = &email_service { if let Some(es) = &email_service {
if let Err(e) = es.send_fcm_failure_alert(&device_name, &err.to_string()).await { if let Err(e) = es
.send_fcm_failure_alert(&device_name, &err.to_string())
.await
{
eprintln!("Failed to send alert email: {}", e); eprintln!("Failed to send alert email: {}", e);
} }
} }