Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neozhu committed Jan 3, 2025
1 parent 2b5f358 commit 667f552
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
Tenants = await ApiClientServiceProxy.QueryAsync("multitenant", () => ApiClient.Tenants.GetAsync(), tags: null, TimeSpan.FromMinutes(60));
Tenants = await ApiClientServiceProxy.QueryAsync("multitenant", () => ApiClient.Tenants.GetAsync(), tags: null, expiration: TimeSpan.FromMinutes(60));
StateHasChanged(); // Trigger a re-render after the tenants are loaded
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

@using Net.Codecrete.QrCodeGenerator
@using Net.Codecrete.QrCodeGenerator
<div class="d-flex flex-column gap-2">
<MudText Typo="Typo.h4">@L["Two-factor authentication"]</MudText>
<MudDivider />
Expand All @@ -22,10 +21,10 @@
<MudIcon Icon="@Icons.Material.Filled.Phone"></MudIcon> <MudText Color="Color.Primary">@L["Authenticator app"]</MudText>
</div>
<MudText Typo="Typo.body2" Class="mud-text-secondary">@L["Use an authentication app or browser extension to get two-factor authentication codes when prompted."]</MudText>
@if (UserProfileStore.Profile?.IsTwoFactorEnabled??false)
@if (UserProfileStore.Profile?.IsTwoFactorEnabled ?? false)
{
<div class="d-flex flex-row gap-2 align-content-center align-center">
<MudIcon Color="Color.Success" Icon="@Icons.Material.Filled.CheckCircle"> </MudIcon>
<MudIcon Color="Color.Success" Icon="@Icons.Material.Filled.CheckCircle"> </MudIcon>
<MudText Typo="Typo.body2" Class="mud-text-secondary"> @L["To disable, click here."] </MudText>
<MudButton Color="Color.Primary" OnClick="Disable2fa"><MudText>@L["Disable"]</MudText></MudButton>
</div>
Expand Down Expand Up @@ -137,7 +136,7 @@
UserProfileStore.Set(profile);
Snackbar.Add(L["Two-factor authentication has been disabled successfully"], Severity.Success);
}
catch(ProblemDetails e)
catch (ProblemDetails e)
{
Snackbar.Add(e.Detail, Severity.Error);
}
Expand All @@ -156,7 +155,7 @@
}
if (value)
{
var response = await ApiClient.Account.GenerateAuthenticator.GetAsync(q=>q.QueryParameters.AppName= AppSettings.AppName);
var response = await ApiClient.Account.GenerateAuthenticator.GetAsync(q => q.QueryParameters.AppName = AppSettings.AppName);
if (response is not null)
{
_showConfigureAuthenticatorAppDialog = true;
Expand All @@ -167,7 +166,7 @@
}
}
}
public Task Close()
public Task Close()
{
_showConfigureAuthenticatorAppDialog = false;
return Task.CompletedTask;
Expand All @@ -183,7 +182,7 @@
_showConfigureAuthenticatorAppDialog = false;
Snackbar.Add(L["Two-factor authentication has been enabled successfully"], Severity.Success);
}
catch(ApiException e)
catch (ApiException e)
{
if (e.ResponseStatusCode == 404)
{
Expand All @@ -194,7 +193,7 @@
Snackbar.Add(L["Invalid verification code"], Severity.Error);
}
}

}
private async Task GenerateRecoveryCodes()
{
Expand Down
4 changes: 4 additions & 0 deletions src/CleanAspire.ClientApp/Services/ApiClientServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class ApiClientServiceProxy(ILogger<ApiClientServiceProxy> logger, Indexe
cacheKey = $"{cacheKey}";
return await cache.GetOrSetAsync(IndexedDbCache.DATABASENAME, cacheKey, factory, tags, expiration);
}
public async Task ClearCache(string[] tags)
{
await cache.DeleteDataByTagsAsync(IndexedDbCache.DATABASENAME, tags);
}
public async Task<OneOf<TResponse, HttpValidationProblemDetails, ProblemDetails>> ExecuteAsync<TResponse>(Func<Task<TResponse>> apiCall)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ public async Task SaveOrUpdatePaginatedProductsAsync(string cacheKey, PaginatedR
{
return await _cache.GetDataAsync<PaginatedResultOfProductDto>(DATABASENAME, cacheKey);
}

public async Task<PaginatedResultOfProductDto?> GetOrSetAsync(string cacheKey, Func<Task<PaginatedResultOfProductDto?>> factory, TimeSpan? expiration = null)
{
cacheKey = $"{PAGINATION_CACHE_TAG}{cacheKey}";
return await _cache.GetOrSetAsync(DATABASENAME, cacheKey, factory, new[] { PAGINATION_CACHE_TAG }, expiration);
}

public async Task<Dictionary<string, PaginatedResultOfProductDto>> GetAllCachedPaginatedResultsAsync()
{
var cachedData = await _cache.GetDataByTagsAsync<PaginatedResultOfProductDto>(
Expand Down Expand Up @@ -155,10 +148,7 @@ public async Task ClearCommands()
await _cache.DeleteDataAsync(DATABASENAME, OFFLINE_UPDATE_COMMAND_CACHE_KEY);
await _cache.DeleteDataAsync(DATABASENAME, OFFLINE_DELETE_COMMAND_CACHE_KEY);
}
public async Task ClearPaginatedCache()
{
await _cache.DeleteDataByTagsAsync(DATABASENAME, new[] { PAGINATION_CACHE_TAG });
}

private string GenerateProductCacheKey(string productId)
{
return $"{nameof(ProductDto)}:{productId}";
Expand Down
21 changes: 12 additions & 9 deletions src/CleanAspire.ClientApp/Services/Products/ProductServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ public class ProductServiceProxy
private readonly NavigationManager _navigationManager;
private readonly ProductCacheService _productCacheService;
private readonly IWebpushrService _webpushrService;
private readonly ApiClientServiceProxy _apiClientServiceProxy;
private readonly ApiClient _apiClient;

private readonly OnlineStatusInterop _onlineStatusInterop;
private readonly OfflineModeState _offlineModeState;
private readonly OfflineSyncService _offlineSyncService;
private readonly string[] _cacheTags = new[] { "caching" };
private bool _previousOnlineStatus;

private readonly TimeSpan _cacheExpiration = TimeSpan.FromSeconds(15);

public ProductServiceProxy(NavigationManager navigationManager, ProductCacheService productCacheService, IWebpushrService webpushrService, ApiClient apiClient, OnlineStatusInterop onlineStatusInterop, OfflineModeState offlineModeState, OfflineSyncService offlineSyncService)
public ProductServiceProxy(NavigationManager navigationManager, ProductCacheService productCacheService, IWebpushrService webpushrService, ApiClientServiceProxy apiClientServiceProxy, ApiClient apiClient, OnlineStatusInterop onlineStatusInterop, OfflineModeState offlineModeState, OfflineSyncService offlineSyncService)
{
_navigationManager = navigationManager;
_productCacheService = productCacheService;
_webpushrService = webpushrService;
_apiClientServiceProxy = apiClientServiceProxy;
_apiClient = apiClient;
_onlineStatusInterop = onlineStatusInterop;
_offlineModeState = offlineModeState;
Expand Down Expand Up @@ -66,7 +69,7 @@ public async Task<PaginatedResultOfProductDto> GetPaginatedProductsAsync(Product
}
try
{
var paginatedProducts = await _productCacheService.GetOrSetAsync(cacheKey, () => _apiClient.Products.Pagination.PostAsync(paginationQuery), _cacheExpiration);
var paginatedProducts = await _apiClientServiceProxy.QueryAsync($"_{cacheKey}", () => _apiClient.Products.Pagination.PostAsync(paginationQuery), tags: _cacheTags, expiration: _cacheExpiration);
if (paginatedProducts != null && _offlineModeState.Enabled)
{
await _productCacheService.SaveOrUpdatePaginatedProductsAsync(cacheKey, paginatedProducts);
Expand Down Expand Up @@ -97,7 +100,7 @@ public async Task<OneOf<ProductDto, KeyNotFoundException>> GetProductByIdAsync(s
}
try
{
var product = await _apiClient.Products[productId].GetAsync();
var product = await _apiClientServiceProxy.QueryAsync($"_{productId}", () => _apiClient.Products[productId].GetAsync(), tags: _cacheTags, expiration: _cacheExpiration);
if (product != null && _offlineModeState.Enabled)
{
await _productCacheService.SaveOrUpdateProductAsync(product);
Expand Down Expand Up @@ -125,7 +128,7 @@ await _webpushrService.SendNotificationAsync(
$"Our new product, {response.Name}, is now available. Click to learn more!",
productUrl
);
await _productCacheService.ClearPaginatedCache();
await _apiClientServiceProxy.ClearCache(_cacheTags);
return response;
}
catch (HttpValidationProblemDetails ex)
Expand Down Expand Up @@ -203,7 +206,7 @@ public async Task<OneOf<bool, HttpValidationProblemDetails, ProblemDetails>> Upd
try
{
var response = await _apiClient.Products.PutAsync(command);
await _productCacheService.ClearPaginatedCache();
await _apiClientServiceProxy.ClearCache(_cacheTags);
return true;
}
catch (HttpValidationProblemDetails ex)
Expand All @@ -219,7 +222,7 @@ public async Task<OneOf<bool, HttpValidationProblemDetails, ProblemDetails>> Upd
return new ProblemDetails
{
Title = ex.Message,
Detail = ex.InnerException?.Message?? ex.Message
Detail = ex.InnerException?.Message ?? ex.Message
};
}
catch (Exception ex)
Expand Down Expand Up @@ -286,10 +289,10 @@ public async Task<OneOf<bool, ProblemDetails>> DeleteProductsAsync(List<string>
{
await _apiClient.Products.DeleteAsync(new DeleteProductCommand() { Ids = productIds });
await _productCacheService.UpdateDeletedProductsAsync(productIds);
await _productCacheService.ClearPaginatedCache();
await _apiClientServiceProxy.ClearCache(_cacheTags);
return true;
}
catch(ProblemDetails ex)
catch (ProblemDetails ex)
{
return ex;
}
Expand Down Expand Up @@ -362,7 +365,7 @@ async Task ProcessCommandsAsync<T>(IEnumerable<T> commands, Func<T, Task> action
await Task.Delay(1200);
}
await _productCacheService.ClearCommands();
await _productCacheService.ClearPaginatedCache();
await _apiClientServiceProxy.ClearCache(_cacheTags);
_offlineSyncService.SetSyncStatus(SyncStatus.Idle, "", 0, 0);
}
}
Expand Down

0 comments on commit 667f552

Please sign in to comment.