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)); }
public async Task <IActionResult> DeleteCharacterAsync(Guid code) => await WithResponseAsync(() => MakeMagicServiceConnector.DeleteCharacterAsync(code, httpClientConfigurationName));
public async Task <IActionResult> UpdateCharacterAsync(Guid code, [FromBody] CharacterRequestMessage requestMessage) => await WithResponseAsync(() => MakeMagicServiceConnector.UpdateCharacterAsync(code, requestMessage, httpClientConfigurationName));
public async Task <IActionResult> GetCharacterAsync([FromQuery] GetCharactersRequestMessage requestMessage) => await WithResponseAsync(() => MakeMagicServiceConnector.GetCharacterAsync(requestMessage, httpClientConfigurationName));