1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Can delete a single notification

This commit is contained in:
2020-07-11 13:47:07 +02:00
parent 7519ce59fc
commit 55dc7a43b0
4 changed files with 50 additions and 3 deletions

View File

@ -660,6 +660,12 @@ impl DeleteQuery {
}
}
/// Add batch conditions
pub fn add_conditions(mut self, conditions: HashMap<String, mysql::Value>) -> Self {
self.conditions.extend(conditions.into_iter());
self
}
/// Add a string condition
pub fn cond_str(mut self, key: &str, value: &str) -> DeleteQuery {
self.conditions.insert(key.to_string(), Value::from(value));

View File

@ -10,7 +10,31 @@ use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibil
use crate::data::user::UserID;
use crate::helpers::database;
/// check out whether a similar notification exists for given specifications
/// Delete notifications
pub fn delete(notification: &PartialNotification) -> ResultBoxError {
// Check if we have to delete a specific notification or a group of similar notifications
let conditions = match notification.id {
Some(id) => {
let mut map = HashMap::new();
map.insert("id".to_string(), mysql::Value::from(id));
map
}
// Delete similar notifications
None => {
notif_to_db(notification, false)
}
};
// Delete the notifications
database::DeleteQuery::new(NOTIFICATIONS_TABLE)
.add_conditions(conditions)
.exec()
}
/// Check out whether a similar notification exists for given specifications
pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
database::QueryInfo::new(NOTIFICATIONS_TABLE)
.add_conditions(&notif_to_db(n, false))