refactor(ReadEnvelopeReceiverQuery): update response to return list instate of sigel instance

This commit is contained in:
tekh 2025-08-22 18:01:31 +02:00
parent a29785f7c7
commit eae83adee4
4 changed files with 11 additions and 10 deletions

View File

@ -42,7 +42,7 @@ namespace EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
/// Die Antwort enthält Details wie den StatusQ, die Zuordnung zwischen Umschlag und Empfänger
/// sowie zusätzliche Metadaten.
/// </remarks>
public record ReadEnvelopeReceiverQuery : IRequest<EnvelopeReceiverDto?>
public record ReadEnvelopeReceiverQuery : IRequest<IEnumerable<EnvelopeReceiverDto>>
{
/// <summary>
///

View File

@ -10,7 +10,7 @@ namespace EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
/// <summary>
///
/// </summary>
public class ReadEnvelopeReceiverQueryHandler : IRequestHandler<ReadEnvelopeReceiverQuery, EnvelopeReceiverDto?>
public class ReadEnvelopeReceiverQueryHandler : IRequestHandler<ReadEnvelopeReceiverQuery, IEnumerable<EnvelopeReceiverDto>>
{
private readonly IRepository<EnvelopeReceiver> _repo;
@ -34,7 +34,7 @@ public class ReadEnvelopeReceiverQueryHandler : IRequestHandler<ReadEnvelopeRece
/// <param name="cancel"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<EnvelopeReceiverDto?> Handle(ReadEnvelopeReceiverQuery request, CancellationToken cancel)
public async Task<IEnumerable<EnvelopeReceiverDto>> Handle(ReadEnvelopeReceiverQuery request, CancellationToken cancel)
{
var q = _repo.Read();
@ -76,12 +76,12 @@ public class ReadEnvelopeReceiverQueryHandler : IRequestHandler<ReadEnvelopeRece
q = q.Where(er => er.Receiver.Signature == rcv.Signature);
}
var er = await q.Include(er => er.Envelope).ThenInclude(e => e.Documents).ThenInclude(d => d.Elements)
var envRcvs = await q.Include(er => er.Envelope).ThenInclude(e => e.Documents).ThenInclude(d => d.Elements)
.Include(er => er.Envelope).ThenInclude(e => e.History)
.Include(er => er.Envelope).ThenInclude(e => e.User)
.Include(er => er.Receiver)
.FirstOrDefaultAsync(cancel);
.ToListAsync(cancel);
return er is null ? null : _mapper.Map<EnvelopeReceiverDto>(er);
return _mapper.Map<IEnumerable<EnvelopeReceiverDto>>(envRcvs);
}
}

View File

@ -23,15 +23,15 @@ public static class TaskExtensions
}
/// <summary>
/// Awaits the specified task and ensures that the result is not <c>null</c> or empty.
/// If the result is <c>null</c> or contains no elements, a <see cref="NotFoundException"/> is thrown.
/// Awaits the specified task and ensures that the result is not <c>empty</c>.
/// If the result contains no elements, a <see cref="NotFoundException"/> is thrown.
/// </summary>
/// <typeparam name="T">The element type of the collection.</typeparam>
/// <param name="task">The task to await.</param>
/// <param name="exceptionMessage">Optional custom exception message.</param>
/// <returns>The awaited collection if it is not <c>null</c> or empty.</returns>
/// <exception cref="NotFoundException">Thrown if the result is <c>null</c> or empty.</exception>
public static async Task<IEnumerable<T>> ThrowIfNull<T>(this Task<IEnumerable<T>?> task, string? exceptionMessage = null)
public static async Task<IEnumerable<T>> ThrowIfNull<T>(this Task<IEnumerable<T>> task, string? exceptionMessage = null)
{
var result = await task;
return result?.Any() ?? false ? result : throw new NotFoundException(exceptionMessage);

View File

@ -23,7 +23,8 @@ public class TestEnvelopeReceiverController : ReadControllerBase<IEnvelopeReceiv
}
[HttpGet]
public async Task<IActionResult> Get([FromQuery] ReadEnvelopeReceiverQuery q) => Ok(await _mediator.Send(q).ThrowIfNull());
public async Task<IActionResult> Get([FromQuery] ReadEnvelopeReceiverQuery q, CancellationToken cancel)
=> Ok(await _mediator.Send(q, cancel).ThrowIfNull());
[HttpGet("verify-access-code/{envelope_receiver_id}")]
public async Task<IActionResult> VerifyAccessCode([FromRoute] string envelope_receiver_id, [FromQuery] string access_code)