diff options
Diffstat (limited to 'src/types/comment.rs')
-rw-r--r-- | src/types/comment.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/types/comment.rs b/src/types/comment.rs index cf94bd3..0836950 100644 --- a/src/types/comment.rs +++ b/src/types/comment.rs @@ -2,7 +2,7 @@ use serde::Serialize; use tracing::instrument; use crate::{ - database::{self, comments}, + database::Database, types::http::{ResponseCode, Result}, }; @@ -16,9 +16,9 @@ pub struct Comment { } impl Comment { - #[instrument()] - pub fn new(user_id: u64, post_id: u64, content: &str) -> Result<Self> { - let Ok(comment) = comments::add_comment(user_id, post_id, content) else { + #[instrument(skip(db))] + pub fn new(db: &Database, user_id: u64, post_id: u64, content: &str) -> Result<Self> { + let Ok(comment) = db.add_comment(user_id, post_id, content) else { tracing::error!("Failed to create comment"); return Err(ResponseCode::InternalServerError.text("Failed to create post")) }; @@ -26,17 +26,17 @@ impl Comment { Ok(comment) } - #[instrument()] - pub fn from_comment_page(page: u64, post_id: u64) -> Result<Vec<Self>> { - let Ok(posts) = database::comments::get_comments_page(page, post_id) else { + #[instrument(skip(db))] + pub fn from_comment_page(db: &Database, page: u64, post_id: u64) -> Result<Vec<Self>> { + let Ok(posts) = db.get_comments_page(page, post_id) else { return Err(ResponseCode::BadRequest.text("Failed to fetch comments")) }; Ok(posts) } - #[instrument()] - pub fn reterieve_all() -> Result<Vec<Self>> { - let Ok(posts) = database::comments::get_all_comments() else { + #[instrument(skip(db))] + pub fn reterieve_all(db: &Database) -> Result<Vec<Self>> { + let Ok(posts) = db.get_all_comments() else { return Err(ResponseCode::InternalServerError.text("Failed to fetch comments")) }; Ok(posts) |