send notifiation to user + vorstand if user completes 'äquatorpreis' or 'fahrtenabzeichen'; Fixes #746
All checks were successful
CI/CD Pipeline / test (push) Successful in 12m33s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped

This commit is contained in:
2025-01-09 11:45:24 +01:00
parent 97dd7794fb
commit d21272d4bb
7 changed files with 181 additions and 43 deletions

View File

@@ -1,9 +1,9 @@
use std::collections::HashMap;
use std::{collections::HashMap, ops::DerefMut};
use crate::model::user::User;
use chrono::Datelike;
use serde::Serialize;
use sqlx::{FromRow, Row, SqlitePool};
use sqlx::{FromRow, Row, Sqlite, SqlitePool, Transaction};
use super::boat::Boat;
@@ -218,7 +218,7 @@ ORDER BY rowed_km DESC, u.name;
.collect()
}
pub async fn total_km(db: &SqlitePool, user: &User) -> Stat {
pub async fn total_km_tx(db: &mut Transaction<'_, Sqlite>, user: &User) -> Stat {
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
let row = sqlx::query(&format!(
"
@@ -233,7 +233,7 @@ WHERE l.distance_in_km IS NOT NULL;
",
user.id
))
.fetch_one(db)
.fetch_one(db.deref_mut())
.await
.unwrap();
@@ -244,7 +244,18 @@ WHERE l.distance_in_km IS NOT NULL;
}
}
pub async fn person(db: &SqlitePool, year: Option<i32>, user: &User) -> Stat {
pub async fn total_km(db: &SqlitePool, user: &User) -> Stat {
let mut tx = db.begin().await.unwrap();
let ret = Self::total_km_tx(&mut tx, user).await;
tx.commit().await.unwrap();
ret
}
pub async fn person_tx(
db: &mut Transaction<'_, Sqlite>,
year: Option<i32>,
user: &User,
) -> Stat {
let year = match year {
Some(year) => year,
None => chrono::Local::now().year(),
@@ -263,7 +274,7 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%';
",
user.id
))
.fetch_one(db)
.fetch_one(db.deref_mut())
.await
.unwrap();
@@ -273,6 +284,13 @@ WHERE l.distance_in_km IS NOT NULL AND l.arrival LIKE '{year}-%';
rowed_km: row.get("rowed_km"),
}
}
pub async fn person(db: &SqlitePool, year: Option<i32>, user: &User) -> Stat {
let mut tx = db.begin().await.unwrap();
let ret = Self::person_tx(&mut tx, year, user).await;
tx.commit().await.unwrap();
ret
}
}
#[derive(Debug, Serialize)]