Added program control endpoints

This commit is contained in:
2026-09-05 10:27:52 +02:00
parent 0a1378fe25
commit a218b19875
12 changed files with 367 additions and 24 deletions
@@ -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);
}