Added program control endpoints
This commit is contained in:
@@ -1,31 +1,10 @@
|
||||
using PostFundManagement.Application.Abstractions;
|
||||
using PostFundManagement.Application.Abstractions.Services;
|
||||
using PostFundManagement.Domain.Errors;
|
||||
|
||||
namespace PostFundManagement.Application.Services.Shared;
|
||||
|
||||
public sealed class IdentityCacheService(IdentityService service, IDistributedCache cache) : ServiceCacheBase, IIdentityService
|
||||
public sealed class IdentityCacheService(IdentityService service) : ServiceCacheBase, IIdentityService
|
||||
{
|
||||
public async ValueTask<Result> UserIsAuthorisedAsync(Guid userId, CancellationToken cancellationToken = default) =>
|
||||
await Result.Try((Func<ValueTask<Result>>)(async () =>
|
||||
{
|
||||
var cacheKey = HashService.ToMd5Hash($"userisauthorised-{userId}").Value;
|
||||
|
||||
var cached = await cache.GetStringAsync(cacheKey);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(cached))
|
||||
{
|
||||
var result = await service.UserIsAuthorisedAsync(userId, cancellationToken); ;
|
||||
|
||||
if (result.IsFailed) return result;
|
||||
|
||||
await cache.SetStringAsync(cacheKey, "true", cacheOptions, cancellationToken);
|
||||
|
||||
return Result.Ok();
|
||||
}
|
||||
|
||||
return cached.Equals("true", StringComparison.OrdinalIgnoreCase)
|
||||
? Result.Ok()
|
||||
: Result.Fail(NotFoundError.New);
|
||||
}));
|
||||
await service.UserIsAuthorisedAsync(userId, cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user