Пример #1
0
        public TagsModule(IArticleReader articleReader)
            : base("/api")
        {
            _articleReader = articleReader;

            Get["/tags"] = o =>
            {
                if (Request.Query.q.HasValue)
                {
                    string query = HttpUtility.UrlDecode(Request.Query.q);
                    var baked = query.Split(',');
                    var result = _articleReader.ArticlesByTags(baked);

                    if (!result.Any()) return HttpStatusCode.NotFound;

                    return Negotiate
                        .WithStatusCode(HttpStatusCode.OK)
                        .WithModel(result);
                }

                return _articleReader.TagCloud();
            };
        }
Пример #2
0
        public SearchModule(IArticleReader articleReader)
        {
            Get["/search"] = o =>
            {
                PageModel.Meta.QueryResult = default(IEnumerable<ArticleModel>);
                PageModel.Meta.Query = string.Empty;

                if (Request.Query.q.HasValue && !string.IsNullOrEmpty(Request.Query.q))
                {
                    string query = HttpUtility.UrlDecode(Request.Query.q);
                    PageModel.Meta.QueryResult = articleReader.ArticlesByFreeText(query);
                    PageModel.Meta.Query = query;
                }

                PageModel.Meta.TagCloud = articleReader.TagCloud();

                return Negotiate
                       .WithView("_layout/search")
                       .WithModel(PageModel)
                       .WithMediaRangeModel("application/json", PageModel);

            };
        }