/// <summary>
        ///     Получает список постов.
        /// </summary>
        /// <returns>Список постов.</returns>
        public IEnumerable <PostModel> GetPosts()
        {
            var query = new GetFeedQuery(HttpClient);

            var queryResult = query.Execute(null);
            var feed        = queryResult.IsSuccessful
                ? Mapper.Map <List <PostModel> >(queryResult.Data)
                : new List <PostModel>();

            return(feed);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <FeedDto> > GetFeedAsync(GetFeedQuery query, CancellationToken token)
        {
            var feedQuery = new FeedAggregateQuery(query.UserId, query.Page, query.Country, null, ItemPageSize);
            var itemsTask = _queryBus.QueryAsync(feedQuery, token);


            var tutorsTask = _tutorFeedService.GetFeedAsync(query, token);
            await Task.WhenAll(itemsTask, tutorsTask);

            return(SortFeed(itemsTask.Result.ToList(),
                            tutorsTask.Result.ToList(),
                            query.Page));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <FeedDto> > GetFeedAsync(GetFeedQuery query, CancellationToken token)
        {
            if (query is null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            return(await _services[query.Filter].GetFeedAsync(query, token));

            //if (query.Filter is null)
            //{
            //    var feedQuery = new FeedAggregateQuery(query.UserId, query.Page, query.Country, query.Course, ItemPageSize);
            //    var itemsTask = _queryBus.QueryAsync(feedQuery, token);
            //    var tutorsTask = GetTutorsFeedAsync(query.UserId, query.Country, query.Page, query.Course, TutorPageSize, token);

            //    await Task.WhenAll(itemsTask, tutorsTask);

            //    return SortFeed(itemsTask.Result.ToList(),
            //        tutorsTask.Result.ToList(),
            //        query.Page);
            //}


            //if (query.Filter == Core.Enum.FeedType.Tutor)
            //{
            //    return await GetTutorsFeedAsync(query.UserId, query.Country, query.Page, query.Course, 21, token);
            //    //await Task.WhenAll(tutorsTask);
            //    //return tutorsTask.Result;
            //}

            //if (query.Filter == Core.Enum.FeedType.Document || query.Filter == Core.Enum.FeedType.Video)
            //{
            //    var feedQuery = new DocumentFeedWithFliterQuery(query.Page, query.UserId, query.Filter, query.Country, query.Course, 21);
            //    var itemsFeed = await _queryBus.QueryAsync(feedQuery, token);
            //    //Query docs/video
            //    return itemsFeed;
            //}

            //if (query.Filter == Core.Enum.FeedType.Question)
            //{
            //    var feedQuery = new QuestionFeedWithFliterQuery(query.Page, query.UserId, query.Country, query.Course, 21);
            //    var itemsFeed = await _queryBus.QueryAsync(feedQuery, token);
            //    //Question query
            //    return itemsFeed;
            //}


            //return null;
        }
Exemplo n.º 4
0
        public async Task GivenValidRequest_WhenTheRequestDoesNotContainArticlesFromQueryParams_ReturnsEmptyViewModelList()
        {
            // Arrange
            var getFeedQuery = new GetFeedQuery(12, 13);

            // Act
            var handler  = new GetFeedQueryHandler(CurrentUserContext, Context, Mapper);
            var response = await handler.Handle(getFeedQuery, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <ArticleViewModelList>();
            response.Articles.ShouldNotBeNull();
            response.Articles.ShouldBeOfType <List <ArticleDto> >();
            response.Articles.ShouldBeEmpty();
        }
Exemplo n.º 5
0
        public async Task GivenValidRequest_WhenTheRequestHasLimitQueryParam_ReturnsLimitedArticleViewModelList()
        {
            // Arrange
            var getFeedQuery = new GetFeedQuery(1, null);

            // Act
            var handler  = new GetFeedQueryHandler(CurrentUserContext, Context, Mapper);
            var response = await handler.Handle(getFeedQuery, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <ArticleViewModelList>();
            response.Articles.ShouldNotBeNull();
            response.Articles.ShouldBeOfType <List <ArticleDto> >();
            response.Articles.ShouldNotBeEmpty();
            response.Articles.Single().Author.Username.ShouldBe("joey.mckenzie");
        }
Exemplo n.º 6
0
        public async Task GivenValidRequest_WhenTheUserIsFollowingAuthorsWithArticles_ReturnsArticleViewModelListOfAuthorsArticles()
        {
            // Arrange
            var getFeedQuery = new GetFeedQuery(null, null);

            // Act
            var handler  = new GetFeedQueryHandler(CurrentUserContext, Context, Mapper);
            var response = await handler.Handle(getFeedQuery, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <ArticleViewModelList>();
            response.Articles.ShouldNotBeNull();
            response.Articles.ShouldBeOfType <List <ArticleDto> >();
            response.Articles.ShouldContain(a => a.Author.Username == "joey.mckenzie");
            response.Articles.FirstOrDefault(a => a.Author.Username == "joey.mckenzie")?.Author.Following.ShouldBeTrue();
            response.Articles.FirstOrDefault(a => a.Author.Username == "joey.mckenzie")?.Favorited.ShouldBeTrue();
            response.Articles.FirstOrDefault(a => a.Author.Username == "joey.mckenzie")?.TagList.ShouldNotBeEmpty();
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Get(string id)
        {
            try
            {
                var query = new GetFeedQuery(id, new Agent
                {
                    BrowserAgent = HttpContext.Request.Headers[HeaderNames.UserAgent].ToString() ?? "",
                    IpAddress    = HttpContext.Connection.RemoteIpAddress.ToString(),
                    Referrer     = HttpContext.Request.Headers[HeaderNames.Referer].ToString() ?? "",
                    Timestamp    = DateTime.Now
                });
                var result = await _mediator.Send(query);

                if (string.IsNullOrEmpty(result))
                {
                    return(NotFound());
                }

                if (Request.Method.Equals("HEAD"))
                {
                    Log.Information("HEAD request found {bytes} bytes", result.Length);
                    Response.ContentLength = result.Length;
                    return(Ok());
                }
                else
                {
                    return(new ContentResult
                    {
                        Content = result,
                        ContentType = "text/xml",
                        StatusCode = StatusCodes.Status200OK
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error building syndication items");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <FeedDto> > GetFeedAsync(GetFeedQuery query, CancellationToken token)
        {
            var feedQuery = new QuestionFeedWithFliterQuery(query.Page, query.UserId, query.Country, null, 21);

            return(await _queryBus.QueryAsync(feedQuery, token));
        }
Exemplo n.º 9
0
        public async Task <IEnumerable <FeedDto> > GetFeedAsync(GetFeedQuery query, CancellationToken token)
        {
            var tutorQuery = new TutorListQuery(query.UserId, query.Country, query.Page, _pageSize);

            return(await _queryBus.QueryAsync(tutorQuery, token).ContinueWith(r => r.Result.Result, token));
        }
Exemplo n.º 10
0
        public Task <IEnumerable <FeedDto> > GetFeedAsync(GetFeedQuery query, CancellationToken token)
        {
            var newQuery = GetFeedWithCourseQuery.FromBase(query);

            return(GetFeedAsync(newQuery, token));
        }