diff --git a/RadiocomDataViewApp/Clients/Live/LiveRadiocomArtistWorkRepository.cs b/RadiocomDataViewApp/Clients/Live/LiveRadiocomArtistWorkRepository.cs index a090053..2968e83 100644 --- a/RadiocomDataViewApp/Clients/Live/LiveRadiocomArtistWorkRepository.cs +++ b/RadiocomDataViewApp/Clients/Live/LiveRadiocomArtistWorkRepository.cs @@ -14,6 +14,7 @@ namespace RadiocomDataViewApp.Clients.Live public class LiveRadiocomArtistWorkRepository : IRadiocomArtistWorkRepository { private const string LOCALSTORAGEKEY_ARTISTWORK_INFO = "artistwork_info-"; + private const string LOCALSTORAGEKEY_ARTISTARTISTWORK_INFO = "artistartistwork_info-"; private readonly IRadiocomArtistRepository _radiocomArtistRepository; private readonly HttpClient _httpClient; private readonly ILocalStorageService _localStorageService; @@ -83,9 +84,28 @@ public async Task> GetArtistWorksAsync() return result; } - public Task> GetArtist_ArtistWorks(int artistId) + public async Task> GetArtist_ArtistWorks(int artistId) { - throw new NotImplementedException(); + List result; + string localStorageKey = LOCALSTORAGEKEY_ARTISTARTISTWORK_INFO + "all"; + TimeCachedObject> cachedObject = await _localStorageService.GetItemAsync>>(localStorageKey); + if (cachedObject == null || cachedObject.NextUpdateHour < DateTimeOffset.UtcNow) + { + result = (await GetArtistWorksAsync()).Where(x => x.ArtistInfo.Id == artistId).ToList(); + DateTimeOffset nextUpdate = TimeCachedObject.CalculateNextUpdateHour(); + cachedObject = new TimeCachedObject>() + { + CachedObject = result, + NextUpdateHour = nextUpdate + }; + await _localStorageService.SetItemAsync(localStorageKey, cachedObject); + } + else + { + result = cachedObject.CachedObject; + } + + return result; } private class ArtistWorkInfosRequest