From 67b54449a1bbde257e9454419e7bb70ebc515c0f Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Thu, 14 Nov 2024 21:43:54 +0000 Subject: implement artwork upload --- src/db/comments.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/db/comments.rs') 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 { 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> { - 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?, + ) } } -- cgit