コード例 #1
0
ファイル: PostsController.cs プロジェクト: josh-perry/postie
        public IActionResult Get(string boardUrl)
        {
            var board = _boardRepository.GetBoardByUrl(boardUrl);

            if (board == null)
            {
                return(NotFound());
            }

            var posts    = _fetchPostService.GetPostsForBoard(board);
            var response = _postResponseMapper.MapDbToResponseList(posts);

            foreach (var post in response)
            {
                post.CommentCount = _commentRepository.GetCommentsCountForPostId(post.ID);
            }

            return(Json(response));
        }
コード例 #2
0
        public IActionResult Get(string username, int recentCommentsCount = 10, int recentPostsCount = 10)
        {
            var user = _userRepository.GetUserByName(username);

            if (user == null)
            {
                return(NotFound());
            }

            var lastComments = _commentRepository.GetLastCommentsByUser(user, recentCommentsCount);
            var lastPosts    = _fetchPostService.GetLastPostsByUser(user, recentPostsCount);

            var userResponse = _userResponseMapper.MapDbToResponse(user);

            userResponse.RecentComments = _commentResponseMapper.MapDbToResponseList(lastComments);
            userResponse.RecentPosts    = _postResponseMapper.MapDbToResponseList(lastPosts);

            foreach (var post in userResponse.RecentPosts)
            {
                post.CommentCount = _commentRepository.GetCommentsCountForPostId(post.ID);
            }

            return(Json(userResponse));
        }