Exemplo n.º 1
0
        public IHttpActionResult RecommendedPosts([FromUri] string AccessToken)
        {
            var UserId = TokenValidator.VerifyToken(AccessToken);

            var UserFollows = UserAuxiliar
                              .Follows(UserId, SQLContext)
                              .Select(x => x.Id);

            var UserTopics = UserAuxiliar.FollowedSubjects(UserId, SQLContext);

            var UserPosts        = PostAuxiliar.PostsByAuthor(UserId);
            var UserMentionPosts = PostAuxiliar.MentionsUser(UserId, SQLContext);

            var FollowsPosts        = PostAuxiliar.PostsByAuthors(UserFollows);
            var FollowsMentionPosts = PostAuxiliar.MentionsUsers(UserFollows);

            var TopicsPosts = PostAuxiliar.PostsBySubjects(UserTopics.Select(x => x.Id));

            var PostComparer = new PostComparer();

            var RecommendedPosts = UserPosts
                                   .Union(UserMentionPosts, PostComparer)
                                   .Union(FollowsPosts, PostComparer)
                                   .Union(FollowsMentionPosts, PostComparer)
                                   .Union(TopicsPosts, PostComparer)
                                   .ToList();

            RecommendedPosts = PostAuxiliar.UpdateOwner(RecommendedPosts, SQLContext);
            RecommendedPosts = GraphAuxiliar.OrderPostsByAffinity(UserId, RecommendedPosts, SQLContext);

            return(Ok(RecommendedPosts));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostComments([FromUri] string PostId)
        {
            var Comments = PostAuxiliar.PostComments(PostId);

            Comments = PostAuxiliar.UpdateOwner(Comments, SQLContext);

            return(Ok(Comments));
        }
Exemplo n.º 3
0
        public IHttpActionResult PostsByProduct([FromUri] int ProductId)
        {
            var Posts = PostAuxiliar.PostsByProduct(ProductId);

            Posts = PostAuxiliar.UpdateOwner(Posts, SQLContext);

            return(Ok(Posts));
        }
Exemplo n.º 4
0
        public IHttpActionResult PostById([FromUri] string PostId)
        {
            var Post = PostAuxiliar.PostById(PostId);

            Post = PostAuxiliar.UpdateOwner(Post, SQLContext);

            return(Ok(Post));
        }
Exemplo n.º 5
0
        public IHttpActionResult PostsByUser([FromUri] int UserId)
        {
            var Posts = PostAuxiliar.PostsByAuthor(UserId);

            Posts = PostAuxiliar.UpdateOwner(Posts, SQLContext);

            var MentionsPosts = PostAuxiliar.MentionsUser(UserId, SQLContext);

            var Response = Posts.Union(MentionsPosts, new PostComparer()).ToList();

            return(Ok(Response));
        }
Exemplo n.º 6
0
        public IHttpActionResult CreatePost([FromBody] Post NewPost, [FromUri] string AccessToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var UserId = TokenValidator.VerifyToken(AccessToken);

            NewPost.UserId = UserId;

            NewPost = PostAuxiliar.UpdateOwner(NewPost, SQLContext);

            NewPost = TreatPostAddons(NewPost);

            NoSQLContext.PostCollection.InsertOne(NewPost);

            Post Parent = default;

            if (NewPost.Parent != null)
            {
                Parent = FindParent(NewPost);

                if (Parent != default)
                {
                    UpdateParent(Parent, NewPost.Id);
                }
            }

            GraphAuxiliar.IncreaseFollowAffinity(NewPost.UserId, NewPost.Mentions, SQLContext);
            GraphAuxiliar.IncreaseTopicAffinity(NewPost.UserId, NewPost.Hashtags, SQLContext);

            if (Parent != default)
            {
                GraphAuxiliar.IncreaseFollowAffinity(NewPost.UserId, Parent.UserId, SQLContext);
                GraphAuxiliar.IncreaseFollowAffinity(NewPost.UserId, Parent.Mentions, SQLContext);
                GraphAuxiliar.IncreaseTopicAffinity(NewPost.UserId, Parent.Hashtags, SQLContext);
            }

            return(Ok(NewPost));
        }