public async Task <IActionResult> Get([FromRoute] Guid id)
        {
            var quadraResponse = CacheServico
                                 .GetCachedResponse <Response <QuadraResponse> >(
                ApiRotas.Quadra.Get.Replace("{id}", id.ToString()));

            if (quadraResponse is null)
            {
                var quadra = await _quadraServico
                             .ObterQuadraPorIdAsync(id);

                if (quadra is null)
                {
                    return(NotFound());
                }

                quadraResponse = new Response <QuadraResponse>(
                    Mapper.Map <QuadraResponse>(quadra));

                CacheServico.SetCacheResponse(
                    ApiRotas.Quadra.Get.Replace("{id}", id.ToString()),
                    quadraResponse, TimeSpan.FromMinutes(2));
            }

            return(Ok(quadraResponse));
        }
        public async Task <IActionResult> GetAll([FromQuery] PaginacaoQuery pagination)
        {
            var quadrasResponse = CacheServico
                                  .GetCachedResponse <IReadOnlyList <QuadraResponse> >(
                ApiRotas.Quadra.GetAll);

            if (quadrasResponse is null)
            {
                var quadra = await _quadraServico
                             .ObterQuadrasAsync(pagination);

                quadrasResponse = Mapper
                                  .Map <IReadOnlyList <QuadraResponse> >(quadra);

                CacheServico.SetCacheResponse(
                    ApiRotas.Quadra.GetAll,
                    quadrasResponse,
                    TimeSpan.FromMinutes(2));
            }

            if (pagination == null || pagination.NumeroPagina < 1 || pagination.QuantidadePagina < 1)
            {
                return(Ok(new PagedResponse <QuadraResponse>(quadrasResponse)));
            }

            var paginationResponse = PaginationHelpers
                                     .CriarRespostaPaginada(UriServico, pagination, quadrasResponse.ToList());

            return(Ok(paginationResponse));
        }
示例#3
0
        public async Task <IActionResult> Get([FromRoute] Guid id)
        {
            var timeResponse = CacheServico
                               .GetCachedResponse <Response <TimeResponse> >(
                ApiRotas.Time.Get.Replace("{id}", id.ToString()));

            if (timeResponse is null)
            {
                var time = await _timeServico
                           .ObterTimePorIdAsync(id);

                if (time is null)
                {
                    return(NotFound());
                }

                timeResponse = new Response <TimeResponse>(Mapper
                                                           .Map <TimeResponse>(time));

                CacheServico.SetCacheResponse(
                    ApiRotas.Time.Get.Replace("{id}", id.ToString()),
                    timeResponse, TimeSpan.FromMinutes(2));
            }

            return(Ok(timeResponse));
        }
示例#4
0
        public async Task <IActionResult> Get([FromRoute] Guid id)
        {
            var usuarioResponse = CacheServico
                                  .GetCachedResponse <Response <UsuarioResponse> >(
                ApiRotas.Usuario.Get.Replace("{id}", id.ToString()));

            if (usuarioResponse is null)
            {
                var usuario = await _usuarioServico
                              .ObterUsuarioPorIdAsync(id);

                if (usuario is null)
                {
                    return(NotFound());
                }

                usuarioResponse = new Response <UsuarioResponse>(Mapper
                                                                 .Map <UsuarioResponse>(usuario));

                CacheServico.SetCacheResponse(
                    ApiRotas.Usuario.Get.Replace("{id}", id.ToString()),
                    usuarioResponse, TimeSpan.FromMinutes(2));
            }

            return(Ok(usuarioResponse));
        }
示例#5
0
        public async Task <IActionResult> GetAll([FromQuery] PaginacaoQuery pagination, [FromServices] IUriServico uriServico)
        {
            var usuariosResponse = CacheServico
                                   .GetCachedResponse <IReadOnlyList <UsuarioResponse> >(
                ApiRotas.Usuario.GetAll);

            if (usuariosResponse is null)
            {
                var usuarios = await _usuarioServico
                               .ObterUsuariosAsync(pagination);

                usuariosResponse = Mapper
                                   .Map <IReadOnlyList <UsuarioResponse> >(usuarios);

                CacheServico.SetCacheResponse(
                    ApiRotas.Usuario.GetAll,
                    usuariosResponse,
                    TimeSpan.FromMinutes(2));
            }

            if (pagination == null || pagination.NumeroPagina < 1 || pagination.QuantidadePagina < 1)
            {
                return(Ok(new PagedResponse <UsuarioResponse>(usuariosResponse)));
            }

            var paginationResponse = PaginationHelpers
                                     .CriarRespostaPaginada(uriServico, pagination, usuariosResponse.ToList());

            return(Ok(paginationResponse));
        }
        public async Task <IActionResult> Get([FromRoute] Guid id)
        {
            var partidaResponse = CacheServico
                                  .GetCachedResponse <Response <PartidaResponse> >(
                ApiRotas.Partida.Get.Replace("{id}", id.ToString()));

            if (partidaResponse is null)
            {
                var partida = await _partidaService
                              .ObterPartidaPorIdAsync(id);

                if (partida is null)
                {
                    return(NotFound());
                }

                partidaResponse = new Response <PartidaResponse>(
                    Mapper.Map <PartidaResponse>(partida));

                CacheServico.SetCacheResponse(
                    ApiRotas.Partida.Get.Replace("{id}", id.ToString()),
                    partidaResponse, TimeSpan.FromMinutes(2));
            }

            return(Ok(partidaResponse));
        }