Esempio n. 1
0
        public async Task <List <UserPostsDto> > GetUserPosts(IdOrUsernameDto input)
        {
            var result = await _postRepository.GetAll().
                         Where(x => x.IsDeleted == false && x.User.Username == input.Username).
                         Include(x => x.Community).Select(
                x => new UserPostsDto
            {
                Id               = x.Id,
                Slug             = x.Slug,
                Content          = x.Content,
                LinkUrl          = x.LinkUrl,
                UserPostVote     = x.Votes.FirstOrDefault(p => p.IsDeleted == false && p.UserId == input.Id && p.PostId == x.Id),
                MediaContentPath = x.MediaContentPath == null ? null : BlobService.BlobService.GetImageUrl(x.MediaContentPath),
                ContentType      = x.ContentType,
                CreatedDateTime  = x.CreatedDate,
                VoteCount        = x.Votes.Count(v => v.IsDeleted == false && v.Value == 1) - x.Votes.Count(v => v.IsDeleted == false && v.Value == -1),
                Comments         = x.Comments.Where(f => f.IsDeleted == false).Select(f => new Comment
                {
                    ReplyCount = f.Replies.Count(v => v.IsDeleted == false)
                }).ToList(),
                Community = new PostCommunityDto
                {
                    Slug     = x.Community.Slug,
                    Name     = x.Community.Name,
                    LogoPath = BlobService.BlobService.GetImageUrl(x.Community.LogoPath)
                }
            }).OrderByDescending(x => x.Id).ToListAsync();

            return(result);
        }
Esempio n. 2
0
        public async Task <IActionResult> GetUserPosts([FromQuery] IdOrUsernameDto input)
        {
            var token = GetToken();

            if (!String.IsNullOrEmpty(token))
            {
                var userId = LoginHelper.GetClaim(token, "UserId");
                input.Id = Guid.Parse(userId);
            }

            if (input.Id == null)
            {
                input.Id = Guid.Empty;
            }

            var post = await _postAppService.GetUserPosts(input);

            return(Ok(post));
        }