mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Propagate comments update events
This commit is contained in:
@ -6,10 +6,11 @@ use crate::constants::database_tables_names::COMMENTS_TABLE;
|
||||
use crate::data::comment::Comment;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::{database, likes_helper};
|
||||
use crate::helpers::{database, likes_helper, events_helper};
|
||||
use crate::helpers::likes_helper::LikeType;
|
||||
use crate::utils::date_utils::mysql_date;
|
||||
use crate::utils::user_data_utils::user_data_path;
|
||||
use crate::helpers::events_helper::Event;
|
||||
|
||||
/// Create a new comment. In case of success, this function returns the ID of the created comment
|
||||
pub fn create(c: &Comment) -> ResultBoxError<u64> {
|
||||
@ -23,7 +24,8 @@ pub fn create(c: &Comment) -> ResultBoxError<u64> {
|
||||
.insert()?
|
||||
.ok_or(ExecError::new("No ID returned after comment creation!"))?;
|
||||
|
||||
// TODO : emit an event
|
||||
// Emit an event
|
||||
events_helper::propagate_event(&Event::NewComment(&get_single(comment_id)?))?;
|
||||
|
||||
Ok(comment_id)
|
||||
}
|
||||
@ -71,7 +73,8 @@ pub fn edit(comment_id: u64, new_content: &str) -> ResultBoxError {
|
||||
.set_str("commentaire", new_content)
|
||||
.exec()?;
|
||||
|
||||
// TODO : emit an event
|
||||
// Emit an event
|
||||
events_helper::propagate_event(&Event::UpdatedComment(&get_single(comment_id)?))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -94,7 +97,8 @@ pub fn delete(c: &Comment) -> ResultBoxError {
|
||||
.cond_u64("ID", c.id)
|
||||
.exec()?;
|
||||
|
||||
// TODO : emit an event
|
||||
// Emit an event
|
||||
events_helper::propagate_event(&Event::DeletedComment(c))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
|
||||
use crate::data::error::Res;
|
||||
use crate::data::conversation_message::ConversationMessage;
|
||||
use crate::controllers::conversations_controller;
|
||||
use crate::controllers::{conversations_controller, comments_controller};
|
||||
use crate::data::comment::Comment;
|
||||
|
||||
pub enum Event<'a> {
|
||||
|
||||
@ -19,6 +20,15 @@ pub enum Event<'a> {
|
||||
/// Deleted a conversation message
|
||||
DeleteConversationMessage(&'a ConversationMessage),
|
||||
|
||||
/// Created a new comment
|
||||
NewComment(&'a Comment),
|
||||
|
||||
/// Updated a comment
|
||||
UpdatedComment(&'a Comment),
|
||||
|
||||
/// Deleted a comment
|
||||
DeletedComment(&'a Comment),
|
||||
|
||||
/// No event
|
||||
None,
|
||||
}
|
||||
@ -26,5 +36,6 @@ pub enum Event<'a> {
|
||||
/// Propagate an event through the different components of the application
|
||||
pub fn propagate_event(e: &Event) -> Res {
|
||||
conversations_controller::handle_event(e)?;
|
||||
comments_controller::handle_event(e)?;
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user