mirror of
https://github.com/AppFlowy-IO/AppFlowy-Cloud.git
synced 2025-04-19 03:24:42 -04:00
fix: delete reaction from comment SQL query should be based on comment id, not view id
This commit is contained in:
parent
b108325c7c
commit
b6c9f541e2
4 changed files with 14 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n DELETE FROM af_published_view_reaction\n WHERE view_id = $1 AND created_by = (SELECT uid FROM af_user WHERE uuid = $2) AND reaction_type = $3\n ",
|
||||
"query": "\n DELETE FROM af_published_view_reaction\n WHERE comment_id = $1 AND created_by = (SELECT uid FROM af_user WHERE uuid = $2) AND reaction_type = $3\n ",
|
||||
"describe": {
|
||||
"columns": [],
|
||||
"parameters": {
|
||||
|
@ -12,5 +12,5 @@
|
|||
},
|
||||
"nullable": []
|
||||
},
|
||||
"hash": "3bf9811b3cfc16b677c76acee21342b892cf815954e4516589493aae01555dc0"
|
||||
"hash": "816a026ca4c25329b2fb24d59efde9ab71798ff8b31ce7320e02344d4e8b3e42"
|
||||
}
|
|
@ -111,8 +111,8 @@ impl Client {
|
|||
pub async fn create_reaction_on_comment(
|
||||
&self,
|
||||
reaction_type: &str,
|
||||
comment_id: &uuid::Uuid,
|
||||
view_id: &uuid::Uuid,
|
||||
comment_id: &uuid::Uuid,
|
||||
) -> Result<(), AppResponseError> {
|
||||
let url = format!(
|
||||
"{}/api/workspace/published-info/{}/reaction",
|
||||
|
|
|
@ -1365,24 +1365,24 @@ pub async fn insert_reaction_on_comment<'a, E: Executor<'a, Database = Postgres>
|
|||
|
||||
pub async fn delete_reaction_from_comment<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
view_id: &Uuid,
|
||||
comment_id: &Uuid,
|
||||
user_uuid: &Uuid,
|
||||
reaction_type: &str,
|
||||
) -> Result<(), AppError> {
|
||||
let res = sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM af_published_view_reaction
|
||||
WHERE view_id = $1 AND created_by = (SELECT uid FROM af_user WHERE uuid = $2) AND reaction_type = $3
|
||||
WHERE comment_id = $1 AND created_by = (SELECT uid FROM af_user WHERE uuid = $2) AND reaction_type = $3
|
||||
"#,
|
||||
view_id,
|
||||
comment_id,
|
||||
user_uuid,
|
||||
reaction_type,
|
||||
).execute(executor).await?;
|
||||
|
||||
if res.rows_affected() != 1 {
|
||||
tracing::error!(
|
||||
"Failed to delete reaction from published view, view_id: {}, user_id: {}, reaction_type: {}, rows_affected: {}",
|
||||
view_id, user_uuid, reaction_type, res.rows_affected()
|
||||
"Failed to delete reaction from published comment, comment_id: {}, user_id: {}, reaction_type: {}, rows_affected: {}",
|
||||
comment_id, user_uuid, reaction_type, res.rows_affected()
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -454,23 +454,23 @@ async fn test_publish_reactions() {
|
|||
let like_emoji = "👍";
|
||||
let party_emoji = "🎉";
|
||||
page_owner_client
|
||||
.create_reaction_on_comment(like_emoji, &likable_comment_id, &view_id)
|
||||
.create_reaction_on_comment(like_emoji, &view_id, &likable_comment_id)
|
||||
.await
|
||||
.unwrap();
|
||||
let guest_client = localhost_client();
|
||||
let result = guest_client
|
||||
.create_reaction_on_comment(like_emoji, &likable_comment_id, &view_id)
|
||||
.create_reaction_on_comment(like_emoji, &view_id, &likable_comment_id)
|
||||
.await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
||||
|
||||
let (user_client, _) = generate_unique_registered_user_client().await;
|
||||
user_client
|
||||
.create_reaction_on_comment(like_emoji, &likable_comment_id, &view_id)
|
||||
.create_reaction_on_comment(like_emoji, &view_id, &likable_comment_id)
|
||||
.await
|
||||
.unwrap();
|
||||
user_client
|
||||
.create_reaction_on_comment(party_emoji, &party_comment_id, &view_id)
|
||||
.create_reaction_on_comment(party_emoji, &view_id, &party_comment_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -489,12 +489,12 @@ async fn test_publish_reactions() {
|
|||
|
||||
// Test if the reactions are deleted correctly based on view and comment id
|
||||
let result = guest_client
|
||||
.delete_reaction_on_comment(like_emoji, &likable_comment_id, &view_id)
|
||||
.delete_reaction_on_comment(like_emoji, &view_id, &likable_comment_id)
|
||||
.await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
||||
user_client
|
||||
.delete_reaction_on_comment(like_emoji, &likable_comment_id, &view_id)
|
||||
.delete_reaction_on_comment(like_emoji, &view_id, &likable_comment_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue