mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add delete comment functionality with confirmation dialog.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user