Esempio n. 1
0
        public async Task <IActionResult> Get([FromRoute][Required] ConsultarAnuncioRequest request)
        {
            var consultarAnuncioInput = new ConsultarAnuncioInput(request.IdAnuncio);
            await _consultarAnuncioUseCase.Execute(consultarAnuncioInput);

            return(_consultarAnuncioPresenter.ViewModel);
        }
Esempio n. 2
0
        public async Task Execute(ConsultarAnuncioInput consultarAnuncioInput)
        {
            if (consultarAnuncioInput.Id == 0)
            {
                _outputHandler.NotFound($"Codigo do anuncio inválido.");
                return;
            }

            IAnuncio anuncio     = null;
            string   anuncioJson = _cache.GetString($"Anuncio:{consultarAnuncioInput.Id}");

            if (anuncioJson == null)
            {
                anuncio = await _anuncioRepository.Get(consultarAnuncioInput.Id);
            }

            if (anuncio == null)
            {
                _outputHandler.NotFound($"Anuncio não encontrado.");
                return;
            }

            if (anuncioJson == null)
            {
                anuncioJson = JsonConvert.SerializeObject(anuncio);
                DistributedCacheEntryOptions opcoesCache = new DistributedCacheEntryOptions();
                opcoesCache.SetAbsoluteExpiration(TimeSpan.FromMinutes(5));
                _cache.SetString($"Anuncio:{anuncio.ID}", anuncioJson, opcoesCache);
            }

            ConsultarAnuncioOutput consultarAnuncioOutput = new ConsultarAnuncioOutput(anuncio);

            _outputHandler.Default(consultarAnuncioOutput);
        }