change LoadEnvelope method
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using EnvelopeGenerator.Application.Dto.EnvelopeReceiver;
|
||||
using EnvelopeGenerator.Application.Envelopes.Queries;
|
||||
using EnvelopeGenerator.Application.Exceptions;
|
||||
using EnvelopeGenerator.Application.Extensions;
|
||||
using EnvelopeGenerator.Application.Receivers.Queries;
|
||||
using EnvelopeGenerator.Extensions;
|
||||
using MediatR;
|
||||
@@ -83,3 +84,12 @@ public record ReadEnvelopeReceiverQuery : IRequest<IEnumerable<EnvelopeReceiverD
|
||||
/// </summary>
|
||||
public ReadReceiverQuery? Receiver { get; set; }
|
||||
};
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static Task<EnvelopeReceiverDto?> ReadEnvelopeReceiverAsync(this IMediator mediator, string key)
|
||||
{
|
||||
var q = new ReadEnvelopeReceiverQuery() { Key = key };
|
||||
return mediator.Send(q).Then(envRcvs => envRcvs.FirstOrDefault());
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,18 @@ public static class TaskExtensions
|
||||
var result = await task;
|
||||
return result?.Any() ?? false ? result : throw new NotFoundException(exceptionMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="I"></typeparam>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="act"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<I> Then<T, I>(this Task<T> task, Func<T, I> act)
|
||||
{
|
||||
var res = await task;
|
||||
return act(res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user