summaryrefslogtreecommitdiff
path: root/src/types/comment.rs
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-02-15 00:01:44 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-02-15 00:01:44 -0500
commitaec4fdecc10be35cde5dc42308960f10bc452187 (patch)
tree67233229c6839c78d1bd3db0147467da30843f44 /src/types/comment.rs
parentbug fixes (diff)
downloadxssbook-aec4fdecc10be35cde5dc42308960f10bc452187.tar.gz
xssbook-aec4fdecc10be35cde5dc42308960f10bc452187.tar.bz2
xssbook-aec4fdecc10be35cde5dc42308960f10bc452187.zip
make database calls 1 conn
Diffstat (limited to 'src/types/comment.rs')
-rw-r--r--src/types/comment.rs20
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)