public GetCommentsResponse GetCommentsByPost(GetCommentsByPostRequest request) { GetCommentsResponse response = new GetCommentsResponse(); response.StatusCode = 200; response.Errors = new List <string>(); var comments = _commentRepository.GetByPostId(request.PostId); List <CommentDTO> dtos = new List <CommentDTO>(); foreach (var comment in comments) { CommentDTO dto = new CommentDTO() { Comment = comment, Username = _userRepository.GetUserById(comment.UserId).Username, SubComments = _commentRepository.GetByParentCommentId(comment.PostId, comment.Id).Count, }; dtos.Add(dto); } response.Comments = dtos; return(response); }
public JsonResult GetByPost([FromQuery] GetCommentsByPostRequest request) { return(Json(_commentService.GetCommentsByPost(request))); }