mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-23 05:49:22 +00:00
Can delete a single notification
This commit is contained in:
parent
7519ce59fc
commit
55dc7a43b0
@ -58,6 +58,19 @@ pub fn mark_seen(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
let notif_id = r.post_notif_id("notifID")?;
|
let notif_id = r.post_notif_id("notifID")?;
|
||||||
let delete_similar = r.post_bool_opt("delete_similar", false);
|
let delete_similar = r.post_bool_opt("delete_similar", false);
|
||||||
|
|
||||||
// TODO : continue implementation
|
// Check if we are targeting a precise notification or an undetermined number of similar
|
||||||
r.success("continue implementation")
|
// notifications
|
||||||
|
if !delete_similar {
|
||||||
|
notifications_helper::delete(
|
||||||
|
&PartialNotification::new()
|
||||||
|
.set_id(notif_id)
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// TODO : implement me
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
r.success("Notification deleted")
|
||||||
}
|
}
|
@ -189,6 +189,10 @@ impl PartialNotification {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_id(&self) -> bool {
|
||||||
|
self.id.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_dest_user_id(mut self, id: &UserID) -> PartialNotification {
|
pub fn set_dest_user_id(mut self, id: &UserID) -> PartialNotification {
|
||||||
self.dest_user_id = Some(id.clone());
|
self.dest_user_id = Some(id.clone());
|
||||||
self
|
self
|
||||||
|
@ -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
|
/// Add a string condition
|
||||||
pub fn cond_str(mut self, key: &str, value: &str) -> DeleteQuery {
|
pub fn cond_str(mut self, key: &str, value: &str) -> DeleteQuery {
|
||||||
self.conditions.insert(key.to_string(), Value::from(value));
|
self.conditions.insert(key.to_string(), Value::from(value));
|
||||||
|
@ -10,7 +10,31 @@ use crate::data::notification::{NotifElemType, NotifEventType, NotifEventVisibil
|
|||||||
use crate::data::user::UserID;
|
use crate::data::user::UserID;
|
||||||
use crate::helpers::database;
|
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> {
|
pub fn similar_exists(n: &PartialNotification) -> ResultBoxError<bool> {
|
||||||
database::QueryInfo::new(NOTIFICATIONS_TABLE)
|
database::QueryInfo::new(NOTIFICATIONS_TABLE)
|
||||||
.add_conditions(¬if_to_db(n, false))
|
.add_conditions(¬if_to_db(n, false))
|
||||||
|
Loading…
Reference in New Issue
Block a user