예제 #1
0
        private RequestResult HandleDocumentationRequest(IDictionary <string, string> args)
        {
            if (!args.ContainsKey("query"))
            {
                return(new RequestResult(
                           @"Expected ""query"" parameter",
                           HttpStatusCode.BadRequest));
            }

            var query  = args["query"];
            var chatId = Convert.ToInt64(args["chatId"]);

            Console.WriteLine($"{DateTime.UtcNow}: Received query {query}");

            object result;

            try
            {
                IEnumerable <string> preferences = _storage.ShowCategories(chatId);
                var info = _infoGetter.GetInfoByQuery(query);
                result = new Dictionary <string, HashSet <string> >(info.Where(e => preferences.Contains(e.Key)));
            }
            catch (Exception)
            {
                return(new RequestResult(
                           "Not found information by the given query",
                           HttpStatusCode.NotFound));
            }

            Console.WriteLine($"{DateTime.UtcNow}: Handled query {query}");
            _history.AddEntry(chatId, query);
            return(new RequestResult(result));
        }