summaryrefslogtreecommitdiffstats
path: root/src/db/comments.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-11-14 21:43:54 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2024-11-14 21:43:54 +0000
commit67b54449a1bbde257e9454419e7bb70ebc515c0f (patch)
treee23710c2d1f5d219205f26af727b478e455a0071 /src/db/comments.rs
parent469a3ad33914f7eff6edc9ca7fabb12f2950da84 (diff)
downloadcritch-main.tar.gz
critch-main.tar.bz2
critch-main.zip
implement artwork uploadHEADmain
Diffstat (limited to 'src/db/comments.rs')
-rw-r--r--src/db/comments.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/db/comments.rs b/src/db/comments.rs
index ec07aa0..3c14852 100644
--- a/src/db/comments.rs
+++ b/src/db/comments.rs
@@ -13,13 +13,13 @@ impl Comments {
pub async fn create(&self, comment: Comment) -> Result<i32> {
let comment_id = sqlx::query!(
- r#"insert into comments (text, artwork_id) values ($1, $2) returning id"#,
+ r#"insert into comments (text, artwork_id) values ($1, $2) returning comment_id"#,
comment.text,
comment.artwork_id
)
.fetch_one(&self.0)
.await?
- .id;
+ .comment_id;
for in_reply_to_id in comment.in_reply_to_ids {
sqlx::query!("insert into comment_relations (artwork_id, in_reply_to_id, comment_id) values ($1, $2, $3)", comment.artwork_id, in_reply_to_id, comment_id).execute(&self.0).await?;
}
@@ -35,8 +35,11 @@ impl Comments {
}
pub async fn read_thread(&self, artwork_id: i32) -> Result<Vec<Comment>> {
- Ok(sqlx::query_as("select * from comments")
- .fetch_all(&self.0)
- .await?)
+ Ok(
+ sqlx::query_as("select * from comments where artwork_id = $1")
+ .bind(artwork_id)
+ .fetch_all(&self.0)
+ .await?,
+ )
}
}