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 RecommendedProducs([FromUri] string AccessToken) { var UserId = TokenValidator.VerifyToken(AccessToken); var Recommendation = GraphAuxiliar.OrderProductsByAffinity(UserId, SQLContext.Products.ToList(), SQLContext); return(Ok(Recommendation)); }
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)); }
public IHttpActionResult Like([FromUri] string AccessToken, [FromUri] string PostId) { var UserId = TokenValidator.VerifyToken(AccessToken); var PostLiked = PostAuxiliar.PostById(PostId); if (PostLiked.Likes.Contains(UserId)) { PostLiked.Likes.Remove(UserId); } else { PostLiked.Likes.Add(UserId); } if (PostLiked.Dislikes.Contains(UserId)) { PostLiked.Dislikes.Remove(UserId); } var Update = Builders <Post> .Update .Set("Likes", PostLiked.Likes) .Set("Dislikes", PostLiked.Dislikes); PostAuxiliar.UpdatePostById(PostLiked.Id, Update); int TotalLikes = PostLiked.Likes.Count; int TotalDeslikes = PostLiked.Dislikes.Count; dynamic Response = new { TotalLikes, TotalDeslikes }; GraphAuxiliar.IncreaseFollowAffinity(UserId, PostLiked.UserId, SQLContext); GraphAuxiliar.IncreaseTopicAffinity(UserId, PostLiked.Hashtags, SQLContext); return(Ok(Response)); }
public IHttpActionResult RelatedSubjects([FromUri] int SubjectId) { var SimilarSubjects = GraphAuxiliar.CalculateSubjectSimilarity(SubjectId, SQLContext); return(Ok(SimilarSubjects)); }