//! # Comments helper //! //! @author Pierre Hubert use crate::constants::database_tables_names::COMMENTS_TABLE; use crate::data::comment::Comment; use crate::data::error::ResultBoxError; use crate::helpers::database; /// Get the comments of a post pub fn get(post_id: u64) -> ResultBoxError> { database::QueryInfo::new(COMMENTS_TABLE) .cond_u64("ID_texte", post_id) .set_order("ID") .exec(db_to_comment) } /// Turn a database entry into a comment object fn db_to_comment(row: &database::RowResult) -> ResultBoxError { Ok(Comment { id: row.get_u64("ID")?, time_sent: row.get_u64("time_insert").unwrap_or(0), user_id: row.get_user_id("ID_personne")?, post_id: row.get_u64("ID_texte")?, content: row.get_str("commentaire")?, image_path: row.get_optional_str("image_commentaire")?, }) }