Refactor repositories and enhance documentation
- Mark `IEmailTemplateRepository` and `_repository` in `ReadEmailTemplateQueryHandler` as obsolete, suggesting the use of `IRepository`. - Update `ResetEmailTemplateCommand` with additional documentation and examples for `Type`. - Change return type of `CreateEnvelopeReceiverCommand` to `IRequest<CreateEnvelopeReceiverResponse>`. - Improve caching methods in `CacheExtensions.cs` for better functionality and clarity. - Add XML documentation to the `Ok` method in `MappingExtensions`. - Make `UserReference` property required in `ReadHistoryResponse`.
This commit is contained in:
parent
1c51fafb69
commit
9756303d6e
@ -7,7 +7,7 @@ namespace EnvelopeGenerator.Application.Contracts.Repositories;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
[Obsolete("Use IRepository")]
|
||||||
public interface IEmailTemplateRepository : ICRUDRepository<EmailTemplate, int>
|
public interface IEmailTemplateRepository : ICRUDRepository<EmailTemplate, int>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -5,20 +5,19 @@ namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset;
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ein Befehl zum Zurücksetzen einer E-Mail-Vorlage auf die Standardwerte.
|
/// Ein Befehl zum Zurücksetzen einer E-Mail-Vorlage auf die Standardwerte.
|
||||||
/// Erbt von <see cref="EmailTemplateQuery"/> und ermöglicht die Angabe einer optionalen ID und eines Typs der E-Mail-Vorlage.
|
/// Erbt von <see cref="EmailTemplateQuery"/> und ermöglicht die Angabe einer optionalen ID und eines Typs der E-Mail-Vorlage.<br/><br/>
|
||||||
|
/// Beispiele:<br/>
|
||||||
|
/// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.<br/>
|
||||||
|
/// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.<br/>
|
||||||
|
/// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.<br/>
|
||||||
|
/// 3 - DocumentCompleted: Benachrichtigung über den Abschluss eines Dokuments.<br/>
|
||||||
|
/// 4 - DocumentAccessCodeReceived: Benachrichtigung über den Erhalt eines Zugangscodes.<br/>
|
||||||
|
/// 5 - DocumentShared: Benachrichtigung über das Teilen eines Dokuments.<br/>
|
||||||
|
/// 6 - TotpSecret: Benachrichtigung über ein TOTP-Geheimnis.<br/>
|
||||||
|
/// 7 - DocumentRejected_ADM (Für den Absender): Mail an den Absender, wenn das Dokument abgelehnt wird.<br/>
|
||||||
|
/// 8 - DocumentRejected_REC (Für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.<br/>
|
||||||
|
/// 9 - DocumentRejected_REC_2 (Für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.<br/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// Beispiele:
|
|
||||||
/// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.
|
|
||||||
/// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.
|
|
||||||
/// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.
|
|
||||||
/// 3 - DocumentCompleted: Benachrichtigung über den Abschluss eines Dokuments.
|
|
||||||
/// 4 - DocumentAccessCodeReceived: Benachrichtigung über den Erhalt eines Zugangscodes.
|
|
||||||
/// 5 - DocumentShared: Benachrichtigung über das Teilen eines Dokuments.
|
|
||||||
/// 6 - TotpSecret: Benachrichtigung über ein TOTP-Geheimnis.
|
|
||||||
/// 7 - DocumentRejected_ADM (Für den Absender): Mail an den Absender, wenn das Dokument abgelehnt wird.
|
|
||||||
/// 8 - DocumentRejected_REC (Für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.
|
|
||||||
/// 9 - DocumentRejected_REC_2 (Für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.
|
|
||||||
/// </param>
|
|
||||||
public record ResetEmailTemplateCommand : EmailTemplateQuery, IRequest
|
public record ResetEmailTemplateCommand : EmailTemplateQuery, IRequest
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -34,7 +33,7 @@ public record ResetEmailTemplateCommand : EmailTemplateQuery, IRequest
|
|||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Id">Die optionale ID der E-Mail-Vorlage, die zurückgesetzt werden soll.</param>
|
/// <param name="Id">Die optionale ID der E-Mail-Vorlage, die zurückgesetzt werden soll.</param>
|
||||||
/// <param name="Type">Der Typ der E-Mail-Vorlage, z. B. <see cref="Constants.EmailTemplateType"/> (optional).
|
/// <param name="Type">Der Typ der E-Mail-Vorlage, z. B. <see cref="Constants.EmailTemplateType"/> (optional).</param>
|
||||||
public ResetEmailTemplateCommand(int? Id = null, Constants.EmailTemplateType? Type = null) : base(Id, Type)
|
public ResetEmailTemplateCommand(int? Id = null, Constants.EmailTemplateType? Type = null) : base(Id, Type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ public class ReadEmailTemplateQueryHandler : IRequestHandler<ReadEmailTemplateQu
|
|||||||
{
|
{
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||||
private readonly IEmailTemplateRepository _repository;
|
private readonly IEmailTemplateRepository _repository;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -21,6 +22,7 @@ public class ReadEmailTemplateQueryHandler : IRequestHandler<ReadEmailTemplateQu
|
|||||||
/// <param name="repository">
|
/// <param name="repository">
|
||||||
/// Die AutoMapper-Instanz, die zum Zuordnen von Objekten verwendet wird.
|
/// Die AutoMapper-Instanz, die zum Zuordnen von Objekten verwendet wird.
|
||||||
/// </param>
|
/// </param>
|
||||||
|
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||||
public ReadEmailTemplateQueryHandler(IMapper mapper, IEmailTemplateRepository repository)
|
public ReadEmailTemplateQueryHandler(IMapper mapper, IEmailTemplateRepository repository)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
@ -34,6 +36,7 @@ public class ReadEmailTemplateQueryHandler : IRequestHandler<ReadEmailTemplateQu
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="InvalidOperationException"></exception>
|
/// <exception cref="InvalidOperationException"></exception>
|
||||||
|
[Obsolete("Use IRepository")]
|
||||||
public async Task<ReadEmailTemplateResponse?> Handle(ReadEmailTemplateQuery request, CancellationToken cancellationToken)
|
public async Task<ReadEmailTemplateResponse?> Handle(ReadEmailTemplateQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var temp = request.Id is int id
|
var temp = request.Id is int id
|
||||||
|
|||||||
@ -18,4 +18,4 @@ public record CreateEnvelopeReceiverCommand(
|
|||||||
[Required] DocumentCreateCommand Document,
|
[Required] DocumentCreateCommand Document,
|
||||||
[Required] IEnumerable<ReceiverGetOrCreateCommand> Receivers,
|
[Required] IEnumerable<ReceiverGetOrCreateCommand> Receivers,
|
||||||
bool TFAEnabled = false
|
bool TFAEnabled = false
|
||||||
) : CreateEnvelopeCommand(Title, Message, TFAEnabled), IRequest<CreateEnvelopeReceiverResponse?>;
|
) : CreateEnvelopeCommand(Title, Message, TFAEnabled), IRequest<CreateEnvelopeReceiverResponse>;
|
||||||
@ -1,131 +1,222 @@
|
|||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Extensions
|
namespace EnvelopeGenerator.Application.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static class CacheExtensions
|
||||||
{
|
{
|
||||||
public static class CacheExtensions
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Task SetLongAsync(this IDistributedCache cache, string key, long value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
||||||
|
=> options is null
|
||||||
|
? cache.SetAsync(key, BitConverter.GetBytes(value), token: cToken)
|
||||||
|
: cache.SetAsync(key, BitConverter.GetBytes(value), options: options, token: cToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<long?> GetLongAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
||||||
{
|
{
|
||||||
public static Task SetLongAsync(this IDistributedCache cache, string key, long value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
var value = await cache.GetAsync(key, cToken);
|
||||||
=> options is null
|
return value is null ? null : BitConverter.ToInt64(value, 0);
|
||||||
? cache.SetAsync(key, BitConverter.GetBytes(value), token: cToken)
|
|
||||||
: cache.SetAsync(key, BitConverter.GetBytes(value), options: options, token: cToken);
|
|
||||||
|
|
||||||
public static async Task<long?> GetLongAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
var value = await cache.GetAsync(key, cToken);
|
|
||||||
return value is null ? null : BitConverter.ToInt64(value, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task SetDateTimeAsync(this IDistributedCache cache, string key, DateTime value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
|
||||||
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken: cToken);
|
|
||||||
|
|
||||||
public static async Task<DateTime?> GetDateTimeAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
var value = await cache.GetAsync(key, cToken);
|
|
||||||
return value is null ? null : new(BitConverter.ToInt64(value, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task SetTimeSpanAsync(this IDistributedCache cache, string key, TimeSpan value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
|
||||||
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken);
|
|
||||||
|
|
||||||
public static async Task<TimeSpan?> GetTimeSpanAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
var value = await cache.GetAsync(key, cToken);
|
|
||||||
return value is null ? null : new(BitConverter.ToInt64(value, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: use code generator
|
|
||||||
#region GetOrSetAsync
|
|
||||||
|
|
||||||
#region string
|
|
||||||
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<string> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
var value = await cache.GetStringAsync(key, cToken);
|
|
||||||
if (value is null)
|
|
||||||
{
|
|
||||||
// create new and save
|
|
||||||
value = factory();
|
|
||||||
|
|
||||||
Task CacheAsync() => options is null
|
|
||||||
? cache.SetStringAsync(key, value, cToken)
|
|
||||||
: cache.SetStringAsync(key, value, options, cToken);
|
|
||||||
|
|
||||||
if (cacheInBackground)
|
|
||||||
_ = Task.Run(async () => await CacheAsync(), cToken);
|
|
||||||
else
|
|
||||||
await CacheAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<string>> factoryAsync, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
var value = await cache.GetStringAsync(key, cToken);
|
|
||||||
if(value is null)
|
|
||||||
{
|
|
||||||
// create new and save
|
|
||||||
value = await factoryAsync();
|
|
||||||
|
|
||||||
Task CacheAsync() => options is null
|
|
||||||
? cache.SetStringAsync(key: key, value: value, token: cToken)
|
|
||||||
: cache.SetStringAsync(key: key, value: value, options: options, token: cToken);
|
|
||||||
|
|
||||||
if (cacheInBackground)
|
|
||||||
_ = Task.Run(async () => await CacheAsync(), cToken);
|
|
||||||
else
|
|
||||||
await CacheAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region DateTime
|
|
||||||
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<DateTime> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
|
|
||||||
return dateTimeValue;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// create new and save
|
|
||||||
var newValue = factory();
|
|
||||||
|
|
||||||
Task CacheAsync() => options is null
|
|
||||||
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
|
|
||||||
: cache.SetDateTimeAsync(key, newValue, options, cToken);
|
|
||||||
|
|
||||||
if (cacheInBackground)
|
|
||||||
_ = Task.Run(async () => await CacheAsync(), cToken);
|
|
||||||
else
|
|
||||||
await CacheAsync();
|
|
||||||
|
|
||||||
return newValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<DateTime>> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
|
||||||
{
|
|
||||||
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
|
|
||||||
return dateTimeValue;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// create new and save
|
|
||||||
var newValue = await factory();
|
|
||||||
|
|
||||||
Task CacheAsync() => options is null
|
|
||||||
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
|
|
||||||
: cache.SetDateTimeAsync(key, newValue, options, cToken);
|
|
||||||
|
|
||||||
if (cacheInBackground)
|
|
||||||
_ = Task.Run(async () => await CacheAsync(), cToken);
|
|
||||||
else
|
|
||||||
await CacheAsync();
|
|
||||||
|
|
||||||
return newValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Task SetDateTimeAsync(this IDistributedCache cache, string key, DateTime value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
||||||
|
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken: cToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<DateTime?> GetDateTimeAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
var value = await cache.GetAsync(key, cToken);
|
||||||
|
return value is null ? null : new(BitConverter.ToInt64(value, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Task SetTimeSpanAsync(this IDistributedCache cache, string key, TimeSpan value, DistributedCacheEntryOptions? options = null, CancellationToken cToken = default)
|
||||||
|
=> cache.SetLongAsync(key: key, value: value.Ticks, options: options, cToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<TimeSpan?> GetTimeSpanAsync(this IDistributedCache cache, string key, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
var value = await cache.GetAsync(key, cToken);
|
||||||
|
return value is null ? null : new(BitConverter.ToInt64(value, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: use code generator
|
||||||
|
#region GetOrSetAsync
|
||||||
|
|
||||||
|
#region string
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="factory"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cacheInBackground"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<string> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
var value = await cache.GetStringAsync(key, cToken);
|
||||||
|
if (value is null)
|
||||||
|
{
|
||||||
|
// create new and save
|
||||||
|
value = factory();
|
||||||
|
|
||||||
|
Task CacheAsync() => options is null
|
||||||
|
? cache.SetStringAsync(key, value, cToken)
|
||||||
|
: cache.SetStringAsync(key, value, options, cToken);
|
||||||
|
|
||||||
|
if (cacheInBackground)
|
||||||
|
_ = Task.Run(async () => await CacheAsync(), cToken);
|
||||||
|
else
|
||||||
|
await CacheAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="factoryAsync"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cacheInBackground"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<string> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<string>> factoryAsync, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
var value = await cache.GetStringAsync(key, cToken);
|
||||||
|
if(value is null)
|
||||||
|
{
|
||||||
|
// create new and save
|
||||||
|
value = await factoryAsync();
|
||||||
|
|
||||||
|
Task CacheAsync() => options is null
|
||||||
|
? cache.SetStringAsync(key: key, value: value, token: cToken)
|
||||||
|
: cache.SetStringAsync(key: key, value: value, options: options, token: cToken);
|
||||||
|
|
||||||
|
if (cacheInBackground)
|
||||||
|
_ = Task.Run(async () => await CacheAsync(), cToken);
|
||||||
|
else
|
||||||
|
await CacheAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DateTime
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="factory"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cacheInBackground"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<DateTime> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
|
||||||
|
return dateTimeValue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// create new and save
|
||||||
|
var newValue = factory();
|
||||||
|
|
||||||
|
Task CacheAsync() => options is null
|
||||||
|
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
|
||||||
|
: cache.SetDateTimeAsync(key, newValue, options, cToken);
|
||||||
|
|
||||||
|
if (cacheInBackground)
|
||||||
|
_ = Task.Run(async () => await CacheAsync(), cToken);
|
||||||
|
else
|
||||||
|
await CacheAsync();
|
||||||
|
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="factory"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <param name="cacheInBackground"></param>
|
||||||
|
/// <param name="cToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<DateTime> GetOrSetAsync(this IDistributedCache cache, string key, Func<Task<DateTime>> factory, DistributedCacheEntryOptions? options = null, bool cacheInBackground = false, CancellationToken cToken = default)
|
||||||
|
{
|
||||||
|
if (await cache.GetDateTimeAsync(key, cToken) is DateTime dateTimeValue)
|
||||||
|
return dateTimeValue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// create new and save
|
||||||
|
var newValue = await factory();
|
||||||
|
|
||||||
|
Task CacheAsync() => options is null
|
||||||
|
? cache.SetDateTimeAsync(key, newValue, cToken: cToken)
|
||||||
|
: cache.SetDateTimeAsync(key, newValue, options, cToken);
|
||||||
|
|
||||||
|
if (cacheInBackground)
|
||||||
|
_ = Task.Run(async () => await CacheAsync(), cToken);
|
||||||
|
else
|
||||||
|
await CacheAsync();
|
||||||
|
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
@ -1,14 +1,27 @@
|
|||||||
using EnvelopeGenerator.Application.DTOs.Messaging;
|
using EnvelopeGenerator.Application.DTOs.Messaging;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Extensions
|
namespace EnvelopeGenerator.Application.Extensions;
|
||||||
{
|
|
||||||
public static class MappingExtensions
|
|
||||||
{
|
|
||||||
public static bool Ok(this GtxMessagingResponse gtxMessagingResponse)
|
|
||||||
=> gtxMessagingResponse.TryGetValue("message-status", out var status)
|
|
||||||
&& status?.ToString()?.ToLower() == "ok";
|
|
||||||
|
|
||||||
public static string ToBase64String(this byte[] bytes)
|
/// <summary>
|
||||||
=> Convert.ToBase64String(bytes);
|
/// Provides extension methods for common mapping and conversion operations.
|
||||||
}
|
/// </summary>
|
||||||
|
public static class MappingExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the response indicates a successful "OK" message status.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gtxMessagingResponse">The response object to evaluate.</param>
|
||||||
|
/// <returns><see langword="true"/> if the response contains a "message-status" key with a value of "ok" (case-insensitive);
|
||||||
|
/// otherwise, <see langword="false"/>.</returns>
|
||||||
|
public static bool Ok(this GtxMessagingResponse gtxMessagingResponse)
|
||||||
|
=> gtxMessagingResponse.TryGetValue("message-status", out var status)
|
||||||
|
&& status?.ToString()?.ToLower() == "ok";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the specified byte array to its equivalent string representation encoded in base-64.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bytes">The byte array to encode.</param>
|
||||||
|
/// <returns>A base-64 encoded string representation of the input byte array.</returns>
|
||||||
|
public static string ToBase64String(this byte[] bytes)
|
||||||
|
=> Convert.ToBase64String(bytes);
|
||||||
}
|
}
|
||||||
@ -10,6 +10,7 @@ namespace EnvelopeGenerator.Application.Histories.Queries.Read;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<ReadHistoryResponse>>
|
public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumerable<ReadHistoryResponse>>
|
||||||
{
|
{
|
||||||
|
[Obsolete("Use IRepository")]
|
||||||
private readonly IEnvelopeHistoryRepository _repository;
|
private readonly IEnvelopeHistoryRepository _repository;
|
||||||
|
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
@ -19,6 +20,7 @@ public class ReadHistoryQueryHandler : IRequestHandler<ReadHistoryQuery, IEnumer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repository"></param>
|
/// <param name="repository"></param>
|
||||||
/// <param name="mapper"></param>
|
/// <param name="mapper"></param>
|
||||||
|
[Obsolete("Use IRepository")]
|
||||||
public ReadHistoryQueryHandler(IEnvelopeHistoryRepository repository, IMapper mapper)
|
public ReadHistoryQueryHandler(IEnvelopeHistoryRepository repository, IMapper mapper)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public class ReadHistoryResponse
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the reference identifier of the user who performed the action.
|
/// Gets or sets the reference identifier of the user who performed the action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserReference { get; set; }
|
public required string UserReference { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the status code of the envelope.
|
/// Gets or sets the status code of the envelope.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user