Enhance query criteria and add partial email matching
- Added `[NotMapped]` attribute to `HasAnyCriteria` in `ReceiverQueryBase` to exclude it from database mapping. - Made `HasAnyCriteria` in `ReceiverQueryBase` virtual for overriding. - Introduced `EmailAddressSearch` in `ReadReceiverQuery` for partial email matching. - Overrode `HasAnyCriteria` in `ReadReceiverQuery` to include `EmailAddressSearch`. - Updated `ReadReceiverQueryHandler` to support partial email matching using `EF.Functions.Like`.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace EnvelopeGenerator.Application.Common.Query;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Common.Query;
|
||||
|
||||
/// <summary>
|
||||
/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen.
|
||||
@@ -29,5 +31,6 @@ public record ReceiverQueryBase
|
||||
/// <see cref="Id"/>, <see cref="EmailAddress"/>, or <see cref="Signature"/> is not null.
|
||||
/// <para>Usage example: The query can be executed only if at least one criterion is specified.</para>
|
||||
/// </remarks>
|
||||
public bool HasAnyCriteria => Id is not null || EmailAddress is not null || Signature is not null;
|
||||
[NotMapped]
|
||||
public virtual bool HasAnyCriteria => Id is not null || EmailAddress is not null || Signature is not null;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using EnvelopeGenerator.Application.Common.Query;
|
||||
using MediatR;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Receivers.Queries;
|
||||
|
||||
@@ -12,7 +13,24 @@ 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.
|
||||
/// </summary>
|
||||
public record ReadReceiverQuery : ReceiverQueryBase, IRequest<IEnumerable<ReceiverDto>>;
|
||||
public record ReadReceiverQuery : ReceiverQueryBase, IRequest<IEnumerable<ReceiverDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// Suchbegriff für eine teilweise Übereinstimmung in der E-Mail Adresse des Empfängers
|
||||
/// </summary>
|
||||
public virtual string? EmailAddressSearch { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether any of the specified query criteria have a value.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This property returns <c>true</c> if at least one of the fields
|
||||
/// <see cref="ReceiverQueryBase.Id"/>, <see cref="ReceiverQueryBase.EmailAddress"/>, <see cref="EmailAddressSearch"/>, or <see cref="ReceiverQueryBase.Signature"/> is not null.
|
||||
/// <para>Usage example: The query can be executed only if at least one criterion is specified.</para>
|
||||
/// </remarks>
|
||||
[NotMapped]
|
||||
public override bool HasAnyCriteria => EmailAddressSearch is not null || base.HasAnyCriteria;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -53,6 +71,11 @@ public class ReadReceiverQueryHandler : IRequestHandler<ReadReceiverQuery, IEnum
|
||||
query = query.Where(r => r.EmailAddress == email);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.EmailAddressSearch))
|
||||
{
|
||||
query = query.Where(r => EF.Functions.Like(r.EmailAddress, $"%{request.EmailAddressSearch}%"));
|
||||
}
|
||||
|
||||
if (request.Signature is string signature)
|
||||
{
|
||||
query = query.Where(r => r.Signature == signature);
|
||||
|
||||
Reference in New Issue
Block a user