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)); }
public IHttpActionResult PostComments([FromUri] string PostId) { var Comments = PostAuxiliar.PostComments(PostId); Comments = PostAuxiliar.UpdateOwner(Comments, SQLContext); return(Ok(Comments)); }
public IHttpActionResult PostsByProduct([FromUri] int ProductId) { var Posts = PostAuxiliar.PostsByProduct(ProductId); Posts = PostAuxiliar.UpdateOwner(Posts, SQLContext); return(Ok(Posts)); }
public IHttpActionResult PostById([FromUri] string PostId) { var Post = PostAuxiliar.PostById(PostId); Post = PostAuxiliar.UpdateOwner(Post, SQLContext); return(Ok(Post)); }
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)); }
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)); }