Surfaced programme rules
This commit is contained in:
@@ -20,6 +20,9 @@ public sealed class ExecutionCacheService(ExecutionService service, IDistributed
|
||||
public async Task<Result> CreateRiskAsync(CreateRiskRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.CreateRiskAsync(request, userId, cancellationToken);
|
||||
|
||||
public async Task<Result> CreateRuleAsync(CreateRuleRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.CreateRuleAsync(request, userId, cancellationToken);
|
||||
|
||||
public async Task<Result<Disbursement>> GetDisbursementAsync(string disbursementIdHash, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<Task<Result<Disbursement>>>)(async () =>
|
||||
{
|
||||
@@ -116,9 +119,60 @@ public sealed class ExecutionCacheService(ExecutionService service, IDistributed
|
||||
return Result.Ok(cached.FromJson<Risk[]>());
|
||||
}));
|
||||
|
||||
public async Task<Result<Rule>> GetRuleAsync(string ruleIdHash, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<Task<Result<Rule>>>)(async () =>
|
||||
{
|
||||
if (!await featureManager.IsEnabledAsync(ServiceCachingFeature))
|
||||
return await service.GetRuleAsync(ruleIdHash, cancellationToken);
|
||||
|
||||
var cacheKey = HashService.ToMd5Hash($"getrisk-{ruleIdHash}").Value;
|
||||
|
||||
var cached = await cache.GetStringAsync(cacheKey, cancellationToken);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(cached))
|
||||
{
|
||||
var result = await service.GetRuleAsync(ruleIdHash, cancellationToken);
|
||||
|
||||
if (result.IsFailed) return result;
|
||||
|
||||
await cache.SetStringAsync(cacheKey, result.Value.ToJson(), cacheOptions, cancellationToken);
|
||||
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
return Result.Ok(cached.FromJson<Rule>());
|
||||
}));
|
||||
|
||||
public async Task<Result<Rule[]>> GetRulesAsync(Pagination pagination, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<Task<Result<Rule[]>>>)(async () =>
|
||||
{
|
||||
if (!await featureManager.IsEnabledAsync(ServiceCachingFeature))
|
||||
return await service.GetRulesAsync(pagination, cancellationToken);
|
||||
|
||||
var cacheKey = HashService.ToMd5Hash($"getrules-{pagination.Page}-{pagination.PageSize}-{pagination.Index}").Value;
|
||||
|
||||
var cached = await cache.GetStringAsync(cacheKey, cancellationToken);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(cached))
|
||||
{
|
||||
var result = await service.GetRulesAsync(pagination, cancellationToken);
|
||||
|
||||
if (result.IsFailed) return result;
|
||||
|
||||
await cache.SetStringAsync(cacheKey, result.Value.ToJson(), cacheOptions, cancellationToken);
|
||||
|
||||
return result.Value;
|
||||
}
|
||||
|
||||
return Result.Ok(cached.FromJson<Rule[]>());
|
||||
}));
|
||||
|
||||
public async Task<Result> UpdateDisbursementAsync(UpdateDisbursementRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.UpdateDisbursementAsync(request, userId, cancellationToken);
|
||||
|
||||
public async Task<Result> UpdateRiskAsync(UpdateRiskRequest request, CancellationToken cancellationToken = default) =>
|
||||
await service.UpdateRiskAsync(request, cancellationToken);
|
||||
|
||||
public async Task<Result> UpdateRuleAsync(UpdateRuleRequest request, Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await service.UpdateRuleAsync(request, userId, cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user