Пример #1
0
        public ActionResult <List <Post> > Get(string userId)
        {
            List <Post> feedPosts = new List <Post>();

            //userId own posts
            var userPostIds = _userService.GetForUser(userId).Posts;

            foreach (var userPostId in userPostIds)
            {
                feedPosts.Add(_postService.GetForPostId(userPostId));
            }

            //Posts to circles I'm Member of
            var circles = _circleService.GetCirclesForUser(userId);

            foreach (var circle in circles)
            {
                var posts = _postService.GetPostsForCircle(circle.CircleId);
                foreach (var post in posts)
                {
                    if (!feedPosts.Contains(post))
                    {
                        feedPosts.Add(post);
                    }
                }
            }

            //Posts from users userId follows
            var followList = _followsService.GetForUser(userId).FollowedUserIds;

            foreach (var user in followList)
            {
                var userPosts = _userService.GetForUser(user).Posts;

                foreach (var userPostId in userPosts)
                {
                    var post = _postService.GetForPostId(userPostId);

                    if (post.IsPublic)
                    {
                        feedPosts.Add(post);
                    }
                }
            }

            return(feedPosts);
        }