mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can create a comment
This commit is contained in:
@ -4,11 +4,27 @@
|
||||
|
||||
use crate::constants::database_tables_names::COMMENTS_TABLE;
|
||||
use crate::data::comment::Comment;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::helpers::{database, likes_helper};
|
||||
use crate::helpers::likes_helper::LikeType;
|
||||
use crate::utils::date_utils::mysql_date;
|
||||
use crate::utils::user_data_utils::user_data_path;
|
||||
|
||||
/// Create a new comment. In case of success, this function returns the ID of the created comment
|
||||
pub fn create(c: &Comment) -> ResultBoxError<u64> {
|
||||
let comment_id = database::InsertQuery::new(COMMENTS_TABLE)
|
||||
.add_u64("ID_texte", c.post_id)
|
||||
.add_user_id("ID_personne", &c.user_id)
|
||||
.add_str("date_envoi", &mysql_date())
|
||||
.add_u64("time_insert", c.time_sent)
|
||||
.add_str("commentaire", &c.content)
|
||||
.add_opt_str("image_commentaire", c.image_path.as_ref())
|
||||
.insert()?
|
||||
.ok_or(ExecError::new("No ID returned after comment creation!"))?;
|
||||
|
||||
Ok(comment_id)
|
||||
}
|
||||
|
||||
/// Get the comments of a post
|
||||
pub fn get(post_id: u64) -> ResultBoxError<Vec<Comment>> {
|
||||
database::QueryInfo::new(COMMENTS_TABLE)
|
||||
|
Reference in New Issue
Block a user