Exemplo n.º 1
0
        public async Task <IActionResult> LocationAsync([FromQuery] string stationOperator = "", [FromQuery] string[] toc = null)
        {
            try
            {
                var tocFilter = new TocFilter(toc);
                if (tocFilter.HasInvalidTocs)
                {
                    _logger.Information("Invalid tocs provided in request {t}", tocFilter.Tocs);
                    return(await Task.FromResult(
                               BadRequest(new ReferenceError($"Invalid tocs provided in request {tocFilter.Tocs}"))));
                }

                var locations = _data.Locations.Locations.Values;
                locations = string.IsNullOrEmpty(stationOperator)
                    ? locations
                    : locations.Where(s => s.StationOperator.Equals(stationOperator));
                locations = tocFilter.NoFilter
                    ? locations
                    : locations.Where(s => s.TocServices.Any(t => tocFilter.IsValid(t)));
                var model = _mapper.Map <IEnumerable <Timetable.Station>, Model.Station[]>(locations);
                if (model.Any())
                {
                    return(await Task.FromResult(Ok(model)));
                }

                return(await Task.FromResult(
                           NotFound(new ReferenceError($"No stations found. Station Operator: {stationOperator} Toc filter: {tocFilter.Tocs}"))));
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error getting locations");
                return(await Task.FromResult(StatusCode(500, new ReferenceError("Server error"))));
            }
        }
Exemplo n.º 2
0
        public void IsValid(string[] tocs, Toc testToc, bool expected)
        {
            var filter = new TocFilter(tocs);

            Assert.Equal(expected, filter.IsValid(testToc));
        }