public async Task <IActionResult> DeleteComment(int commentId, int imagePostId) { _logger.LogInformation("Received comment delete request."); _logger.LogInformation("Comment id: {0}", commentId); User currentUser = _currentUserService.GetCurrentUser(HttpContext); _logger.LogInformation("Requesting user email: {0}", currentUser.Email); if (!await _commentService.CanDelete(commentId, currentUser.Email)) { _logger.LogError("User '{0}' does not have permission to delete comment with id {1}.", currentUser.Email, commentId); return(Forbid()); } if (!await _commentService.Delete(commentId)) { _logger.LogError("Failed to delete comment with id {0}.", commentId); return(NotFound()); } // Publish event. _logger.LogInformation("Publishing comment delete notification."); CommentDeletedResponse commentDeletedResponse = new CommentDeletedResponse() { CommentId = commentId, ImagePostId = imagePostId }; await _notificationService.Publish(new CommentDeletedNotification(commentDeletedResponse)); _logger.LogError("Successfully deleted comment with id {0}.", commentId); return(NoContent()); }
public CommentDeletedNotification(CommentDeletedResponse commentDeletedResponse) { CommentDeletedResponse = commentDeletedResponse; }