Exemplo n.º 1
0
        public async Task <IEnumerable <Game> > GetGamesBetween(
            GameResultQueryParameter queryParameter,
            CancellationToken cancellationToken)
        {
            var team       = queryParameter.Team;
            var opposition = queryParameter.Opposition;
            var offset     = queryParameter.GameOffset;
            var gameType   = queryParameter.ToGameTypeFilter();

            var games = await _gameRepository.GetGamesForTeam(team, cancellationToken);

            if (gameType != GameTypeFilter.All)
            {
                games = gameType == GameTypeFilter.Reg
                    ? games.Where(x => x.GameType == GameType.REG)
                    : games.Where(x => x.GameType != GameType.REG);
            }

            if (!string.IsNullOrWhiteSpace(opposition))
            {
                games = games.Where(x => x.HomeTeam == opposition || x.AwayTeam == opposition);
            }

            games = games.OrderByDescending(x => x.Gameday);

            return(games.Take(offset));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetResults(
            [FromQuery] GameResultQueryParameter queryParameter,
            CancellationToken cancellationToken)
        {
            var errors = queryParameter.Validate();

            if (errors.Count > 0)
            {
                return(BadRequestError(errors));
            }

            var games = await _scheduleService.GetGamesBetween(queryParameter, cancellationToken);

            _logger.LogInformation("Successful Games request");
            _tracer.ActiveSpan.SetTags(
                HttpContext.Request.GetDisplayUrl(),
                HttpContext.Connection.RemoteIpAddress.MapToIPv6().ToString());

            return(Ok(games));
        }