Ejemplo n.º 1
0
        public async Task <IActionResult> GetCharacterAsync(Guid code)
        {
            var key = $"{code}-character";

            var cache = await DistributedCache.GetStringAsync(key);

            if (!string.IsNullOrEmpty(cache))
            {
                return(Ok(JsonConvert.DeserializeObject <Response <CharacterResponseMessage> >(cache)));
            }

            var response = await MakeMagicServiceConnector.GetCharacterAsync(code, httpClientConfigurationName);

            if (!response.HasError)
            {
                await DistributedCache
                .SetStringAsync(key, JsonConvert.SerializeObject(response),
                                new DistributedCacheEntryOptions()
                {
                    SlidingExpiration  = TimeSpan.FromDays(2),
                    AbsoluteExpiration = DateTime.UtcNow.AddDays(4)
                });

                return(Ok(response));
            }

            if (response.Messages.Any(m => m.Type == MessageType.BusinessError))
            {
                return(BadRequest(response));
            }

            return(StatusCode(500, response));
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> DeleteCharacterAsync(Guid code)
 => await WithResponseAsync(() => MakeMagicServiceConnector.DeleteCharacterAsync(code, httpClientConfigurationName));
Ejemplo n.º 3
0
 public async Task <IActionResult> UpdateCharacterAsync(Guid code, [FromBody] CharacterRequestMessage requestMessage)
 => await WithResponseAsync(() => MakeMagicServiceConnector.UpdateCharacterAsync(code, requestMessage, httpClientConfigurationName));
Ejemplo n.º 4
0
 public async Task <IActionResult> GetCharacterAsync([FromQuery] GetCharactersRequestMessage requestMessage)
 => await WithResponseAsync(() => MakeMagicServiceConnector.GetCharacterAsync(requestMessage, httpClientConfigurationName));