change LoadEnvelope method

This commit is contained in:
2025-08-22 20:05:53 +02:00
parent 1577440b77
commit 30e2ac602d
4 changed files with 36 additions and 19 deletions

View File

@@ -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());
}
}

View File

@@ -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);
}
}