1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Can delete a single notification

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

View File

@ -58,6 +58,19 @@ pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult {
let notif_id = r.post_notif_id("notifID")?;
let delete_similar = r.post_bool_opt("delete_similar", false);
// TODO : continue implementation
r.success("continue implementation")
// Check if we are targeting a precise notification or an undetermined number of similar
// notifications
if !delete_similar {
notifications_helper::delete(
&PartialNotification::new()
.set_id(notif_id)
)?;
}
else {
// TODO : implement me
unimplemented!();
}
r.success("Notification deleted")
}

View File

@ -189,6 +189,10 @@ impl PartialNotification {
self
}
pub fn has_id(&self) -> bool {
self.id.is_some()
}
pub fn set_dest_user_id(mut self, id: &UserID) -> PartialNotification {
self.dest_user_id = Some(id.clone());
self

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))