Example #1
0
        public async Task <ActionResult <FollowDTO> > Add(FollowDTO follow)
        {
            var user = await userFinder.FindByClaimsPrincipal(User);

            follow.ObserverId = user.Id;
            var added = await followDTOManager.Add(follow);

            if (added == null)
            {
                return(NoContent());
            }
            return(Ok(added));
        }
Example #2
0
        public async Task <ActionResult <List <PostDTO> > > GetFromUser(int page, int count, string userName, string sort, string sortOrder)
        {
            if (string.IsNullOrEmpty(userName))
            {
                var user = await userFinder.FindByClaimsPrincipal(User);

                if (user == null)
                {
                    return(NotFound());
                }
                userName = user.UserName;
            }
            var list = await postManager.GetUserPosts(count, page, userName, sort, sortOrder);

            return(Ok(list));
        }
Example #3
0
        public async Task <ActionResult <UserStatsDTO> > Get(string userName)
        {
            var user = await userFinder.FindByClaimsPrincipal(User);

            var info = await statsManager.Get(userName, user?.Id);

            if (info == null)
            {
                return(NotFound());
            }
            return(Ok(info));
        }
Example #4
0
        public async Task <ActionResult <List <ConversationDTO> > > Search(string searchString)
        {
            var user = await userFinder.FindByClaimsPrincipal(User);

            var result = await conversationManager.SearchConversations(searchString, user.UserName);

            var userNames = await userFinder.SearchUsernames(searchString);

            var existingPrivateConvUsers = result.Where(c => !c.IsGroup).SelectMany(c => c.UserNames);

            userNames = userNames.Where(name => !existingPrivateConvUsers.Contains(name)).ToList();
            var notExistingConvs = userNames.Select(name => new ConversationDTO
            {
                IsGroup   = false,
                UserNames = new List <string> {
                    name
                }
            });

            result.AddRange(notExistingConvs);
            return(Ok(result));
        }
Example #5
0
        public async Task <ActionResult <CommentDTO> > Add(CommentDTO newComment)
        {
            var user = await userFinder.FindByClaimsPrincipal(User);

            if (user == null)
            {
                return(Unauthorized());
            }
            if (newComment.PostId == 0)
            {
                return(BadRequest());
            }
            newComment.AuthorId = user.Id;
            var added = await commentDTOManager.Add(newComment);

            if (added == null)
            {
                return(BadRequest());
            }
            await postNotifier.SendUpdate(newComment.PostId);

            return(CreatedAtAction(nameof(GetSingle), new { id = added.Id }, added));
        }