mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
delete comments
This commit is contained in:
1 parent
ebf48e20be
commit
003a86cd31
3 files changed
+69
No files matched your search
@@ -0,0 +1,64 @@
|
||||
use sqlx::MySqlPool;
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::comments::CommentToken;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum DeleteCommentAs {
|
||||
Author,
|
||||
Moderator,
|
||||
ObjectOwner,
|
||||
}
|
||||
|
||||
pub async fn delete_comment(
|
||||
comment_token: &CommentToken,
|
||||
delete_as: DeleteCommentAs,
|
||||
mysql_pool: &MySqlPool
|
||||
) -> AnyhowResult<()> {
|
||||
|
||||
match delete_as {
|
||||
DeleteCommentAs::Author => {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE comments
|
||||
SET
|
||||
user_deleted_at = CURRENT_TIMESTAMP
|
||||
WHERE
|
||||
token = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
comment_token
|
||||
)
|
||||
}
|
||||
DeleteCommentAs::Moderator => {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE comments
|
||||
SET
|
||||
mod_deleted_at = CURRENT_TIMESTAMP
|
||||
WHERE
|
||||
token = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
comment_token
|
||||
)
|
||||
}
|
||||
DeleteCommentAs::ObjectOwner => {
|
||||
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE comments
|
||||
SET
|
||||
object_owner_deleted_at = CURRENT_TIMESTAMP
|
||||
WHERE
|
||||
token = ?
|
||||
LIMIT 1
|
||||
"#,
|
||||
comment_token
|
||||
)
|
||||
}
|
||||
}
|
||||
.execute(mysql_pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -14,6 +14,7 @@ pub struct CommentForList {
|
||||
pub user_token: UserToken,
|
||||
pub username: String,
|
||||
pub user_display_name: String,
|
||||
pub user_gravatar_hash: String,
|
||||
|
||||
pub comment_markdown: String,
|
||||
pub comment_rendered_html: String,
|
||||
@@ -48,6 +49,7 @@ SELECT
|
||||
c.user_token as `user_token: tokens::users::user::UserToken`,
|
||||
u.username,
|
||||
u.display_name as user_display_name,
|
||||
u.email_gravatar_hash as user_gravatar_hash,
|
||||
|
||||
c.comment_markdown,
|
||||
c.comment_rendered_html,
|
||||
@@ -95,6 +97,7 @@ LIMIT 50
|
||||
user_token: comment.user_token,
|
||||
username: comment.username,
|
||||
user_display_name: comment.user_display_name,
|
||||
user_gravatar_hash: comment.user_gravatar_hash,
|
||||
comment_markdown: comment.comment_markdown,
|
||||
comment_rendered_html: comment.comment_rendered_html,
|
||||
mod_fields: CommentForListModFields {
|
||||
@@ -118,6 +121,7 @@ pub struct RawCommentForList {
|
||||
pub user_token: UserToken,
|
||||
pub username: String,
|
||||
pub user_display_name: String,
|
||||
pub user_gravatar_hash: String,
|
||||
|
||||
pub comment_markdown: String,
|
||||
pub comment_rendered_html: String,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod comment_entity_token;
|
||||
pub mod delete_comment;
|
||||
pub mod insert_comment;
|
||||
pub mod list_comments_for_entity;
|
||||
Reference in new issue
Block a user