generated from t/malachite
fix: message notification deletion
This commit is contained in:
parent
f3180989af
commit
ff1c739367
4 changed files with 39 additions and 2 deletions
26
src/database/notifications.rs
Normal file
26
src/database/notifications.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use super::DataManager;
|
||||
use oiseau::{params, query_row};
|
||||
use tetratto_core::model::{Error, Result};
|
||||
|
||||
impl DataManager {
|
||||
/// Get the number of notifications a user has for the given tag.
|
||||
pub async fn get_notifications_count_by_tag(&self, user: usize, tag: &str) -> Result<usize> {
|
||||
let conn = match self.0.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_row!(
|
||||
&conn,
|
||||
"SELECT COUNT(*)::int FROM notifications WHERE owner = $1 AND tag = $2",
|
||||
params![&(user as i64), &tag],
|
||||
|x| { Ok(x.get::<usize, i32>(0)) }
|
||||
);
|
||||
|
||||
if let Err(e) = res {
|
||||
return Err(Error::DatabaseError(e.to_string()));
|
||||
}
|
||||
|
||||
Ok(res.unwrap() as usize)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue