Example #1
0
        public GetPostsResponse GetLatest(GetLatestPostsRequest request)
        {
            GetPostsResponse response = new GetPostsResponse();

            response.StatusCode = 200;
            response.Errors     = new List <string>();
            response.Posts      = new List <PostDTO>();
            var posts = _postRepository.GetLatest(request.Start, request.Count);

            foreach (var post in posts)
            {
                var tags        = new List <string>();
                var tagEntities = _tagRepository.GetByPostId(post.Id);
                foreach (var tag in tagEntities)
                {
                    tags.Add(tag.Content);
                }
                PostDTO postWithTags = new PostDTO()
                {
                    Post           = post,
                    Tags           = tags,
                    AuthorUsername = _userRepository.GetUserById(post.UserId).Username,
                };
                response.Posts.Add(postWithTags);
            }
            return(response);
        }
Example #2
0
 public JsonResult GetLatest([FromQuery] GetLatestPostsRequest request)
 {
     return(Json(_postService.GetLatest(request)));
 }