public async Task <IActionResult> GetPostWithUser() { var posts = await _postService.GetPostWithUser(); var postDtos = posts.Select(p => new { p.Id, User = new UserDto(p.User), p.PostCategory, PostDate = p.PostDate == DateTime.Now.Date ? p.PostDate.ToString("HH:mm") : p.PostDate.ToString("MM/dd HH:mm"), p.PostImage, p.PostText, LikeCount = _likeService.CountLike(p.Id), CommentCount = _commentService.CountComment(p.Id) }); return(Ok(postDtos)); }
public async Task <IActionResult> GetUserPostById(int userId, bool category) { int loginuserId = Convert.ToInt32(User.FindFirst(ClaimTypes.NameIdentifier)?.Value); var posts = await _postService.GetUserPost(userId, category); var postDtos = posts.Select(p => new { p.Id, User = new UserDto(p.User), p.PostCategory, PostDate = p.PostDate == DateTime.Now.Date ? p.PostDate.ToString("HH:mm") : p.PostDate.ToString("MM/dd HH:mm"), p.PostImage, p.PostText, LikeCount = _likeService.CountLike(p.Id), UserLike = _likeService.UserFindLike(loginuserId, p.Id) == null ? false : true }); return(Ok(postDtos)); }