Esempio n. 1
0
        public void Test_News_First_Page()
        {
            int total;
            IEnumerable <News> sampleEvents = newsPresentation.GetNews(new List <int>()
            {
                1, 2
            }, "", "", 0, 2, out total);

            Assert.NotNull(sampleEvents);
            Assert.Equal(2, sampleEvents.Count());
        }
Esempio n. 2
0
        public IActionResult GetNews([FromQuery] QueryPagination page, [FromQuery] QueryFilter filter, [FromQuery] string query = "", [FromQuery] string baseUrl = "")
        {
            baseUrl = GetBaseUrl(baseUrl);
            if (filter.categories == 0)
            {
                filter = GetQueryFilter();
            }
            query = GetSearchKey(filter.search, query);

            if (string.IsNullOrEmpty(baseUrl))
            {
                _logger.Error("baseUrl not been provided");
                return(NoContent());
            }

            var schools = _schoolsService.GetSchools(baseUrl, "");

            if (IsResourcesRequestValid(filter, schools, new List <int>()
            {
                1, 2
            }))
            {
                int total;
                var news = _newsPresentation.GetNews(filter.channelServerIds, baseUrl, query, page.offset, page.limit, out total);

                var links = string.IsNullOrEmpty(query) ? this.GetLinks(baseUrl, filter, page, "", true, total) : null;

                if (news.Count() == 0)
                {
                    _logger.Information("no news found");
                    return(Ok(new { Data = schools, Links = links }));
                }

                var dataList = from p in news
                               select new {
                    id         = p.Id.ToString(),
                    type       = "school-messenger.news",
                    attributes = new {
                        title             = p.Title,
                        featuredImage     = string.IsNullOrEmpty(p.FeaturedImage) ? p.FeaturedImage : Uri.EscapeUriString(p.FeaturedImage),
                        imageTitle        = p.ImageTitle,
                        summary           = p.Summary,
                        body              = p.Body,
                        linkOfCurrentPage = p.LinkOfCurrentPage,
                        publishedDate     = p.PublishedDate.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                        pageLastModified  = p.PageLastModified.ToString("yyyy-MM-ddTHH:mm:ssZ"),
                        pageTitle         = p.PageTitle
                    },
                    meta = new {
                        i18n = new {
                            translatableFields = new List <string> {
                                "attributes.title", "attributes.summary", "attributes.body", "attributes.pageTitle"
                            }
                        }
                    },
                    relationships = new {
                        categories = new { data = new object[] { new { type = "school-messenger.categories", id = "2" } } },
                        channels   = new { data = new object[] { new { type = "school-messenger.channels", id = p.ServerId.ToString() } } },
                    }
                };

                return(Ok(new { Data = dataList, Links = links }));
            }

            _logger.Error("validation failed");
            return(NoContent());
        }