Add delete comment functionality with confirmation dialog.

This commit is contained in:
2025-06-23 19:55:43 +08:00
parent 46186e95df
commit dcd23054b2
6 changed files with 145 additions and 1 deletions

View File

@@ -84,3 +84,17 @@ func UpdateComment(commentID, userID uint, content string) (*model.CommentView,
}
return updated.ToView(), nil
}
func DeleteComment(commentID, userID uint) error {
comment, err := dao.GetCommentByID(commentID)
if err != nil {
return model.NewNotFoundError("Comment not found")
}
if comment.UserID != userID {
return model.NewRequestError("You can only delete your own comments")
}
if err := dao.DeleteCommentByID(commentID); err != nil {
return model.NewInternalServerError("Error deleting comment")
}
return nil
}