diff --git a/EnvelopeGenerator.Application/Receivers/Queries/ReadReceiverQuery.cs b/EnvelopeGenerator.Application/Receivers/Queries/ReadReceiverQuery.cs index 7aec9c25..b1255514 100644 --- a/EnvelopeGenerator.Application/Receivers/Queries/ReadReceiverQuery.cs +++ b/EnvelopeGenerator.Application/Receivers/Queries/ReadReceiverQuery.cs @@ -1,4 +1,10 @@ -using EnvelopeGenerator.Application.Common.Query; +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Common.Dto.Receiver; +using EnvelopeGenerator.Application.Common.Query; +using MediatR; +using EnvelopeGenerator.Domain.Entities; +using Microsoft.EntityFrameworkCore; namespace EnvelopeGenerator.Application.Receivers.Queries; @@ -6,4 +12,53 @@ namespace EnvelopeGenerator.Application.Receivers.Queries; /// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen. /// um spezifische Informationen über einen Empfänger abzurufen. /// -public record ReadReceiverQuery : ReceiverQueryBase; \ No newline at end of file +public record ReadReceiverQuery : ReceiverQueryBase, IRequest>; + +/// +/// +/// +public class ReadReceiverQueryHandler : IRequestHandler> +{ + private readonly IRepository _repository; + private readonly IMapper _mapper; + + /// + /// + /// + /// + /// + public ReadReceiverQueryHandler(IRepository repository, IMapper mapper) + { + _repository = repository; + _mapper = mapper; + } + + /// + /// + /// + /// + /// + /// + public async Task> Handle(ReadReceiverQuery request, CancellationToken cancellationToken) + { + var query = _repository.Query; + + if (request.Id is int id) + { + query = query.Where(r => r.Id == id); + } + + if (request.EmailAddress is string email) + { + query = query.Where(r => r.EmailAddress == email); + } + + if (request.Signature is string signature) + { + query = query.Where(r => r.Signature == signature); + } + + var receiver = await query.ToListAsync(cancellationToken); + return _mapper.Map>(receiver); + } +} \ No newline at end of file