fix(QueryExtensions): update to use base classes instead of interfaces

This commit is contained in:
Developer 02 2025-08-26 22:23:26 +02:00
parent f2876d8995
commit ad032b2bdf
4 changed files with 16 additions and 65 deletions

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Application.Interfaces.Model;
using EnvelopeGenerator.Application.Model;
using EnvelopeGenerator.Domain.Interfaces;
@ -14,19 +13,18 @@ public static class QueryExtensions
///
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TEnvelopeQuery"></typeparam>
/// <param name="root"></param>
/// <param name="query"></param>
/// <param name="notnull"></param>
/// <returns></returns>
/// <exception cref="BadRequestException"></exception>
public static IQueryable<TEntity> Where<TEntity, TEnvelopeQuery>(this IQueryable<TEntity> root, IHasEnvelopeQuery<TEnvelopeQuery> query, bool notnull = true)
where TEntity : IHasEnvelope where TEnvelopeQuery : EnvelopeQueryBase
public static IQueryable<TEntity> Where<TEntity>(this IQueryable<TEntity> root, EnvelopeQueryBase query, bool notnull = true)
where TEntity : IHasEnvelope
{
if (query.Envelope.Id is not null)
root = root.Where(e => e.Envelope!.Id == query.Envelope.Id);
else if (query.Envelope.Uuid is not null)
root = root.Where(e => e.Envelope!.Uuid == query.Envelope.Uuid);
if (query.Id is not null)
root = root.Where(e => e.Envelope!.Id == query.Id);
else if (query.Uuid is not null)
root = root.Where(e => e.Envelope!.Uuid == query.Uuid);
else if (notnull)
throw new BadRequestException(
"Either Envelope Id or Envelope Uuid must be provided in the query."
@ -45,15 +43,15 @@ public static class QueryExtensions
/// <param name="notnull"></param>
/// <returns></returns>
/// <exception cref="BadRequestException"></exception>
public static IQueryable<TEntity> Where<TEntity, TReceiverQueryBase>(this IQueryable<TEntity> root, IHasReceiverQuery<TReceiverQueryBase> query, bool notnull = true)
where TEntity : IHasReceiver where TReceiverQueryBase : ReceiverQueryBase
public static IQueryable<TEntity> Where<TEntity, TReceiverQueryBase>(this IQueryable<TEntity> root, ReceiverQueryBase query, bool notnull = true)
where TEntity : IHasReceiver
{
if (query.Receiver.Id is not null)
root = root.Where(e => e.Receiver!.Id == query.Receiver.Id);
else if (query.Receiver.EmailAddress is not null)
root = root.Where(e => e.Receiver!.EmailAddress == query.Receiver.EmailAddress);
else if (query.Receiver.Signature is not null)
root = root.Where(e => e.Receiver!.Signature == query.Receiver.Signature);
if (query.Id is not null)
root = root.Where(e => e.Receiver!.Id == query.Id);
else if (query.EmailAddress is not null)
root = root.Where(e => e.Receiver!.EmailAddress == query.EmailAddress);
else if (query.Signature is not null)
root = root.Where(e => e.Receiver!.Signature == query.Signature);
else if (notnull)
throw new BadRequestException(
"Receiver must have at least one identifier (Id, EmailAddress, or Signature)."

View File

@ -1,23 +0,0 @@
using EnvelopeGenerator.Application.Model;
namespace EnvelopeGenerator.Application.Interfaces.Model;
/// <summary>
///
/// </summary>
public interface IHasEnvelopeQuery<TEnvelopeQuery>
where TEnvelopeQuery : EnvelopeQueryBase
{
/// <summary>
///
/// </summary>
public TEnvelopeQuery Envelope { get; set; }
}
/// <summary>
///
/// </summary>
public interface IHasEnvelopeQuery
: IHasEnvelopeQuery<EnvelopeQueryBase>
{
}

View File

@ -1,23 +0,0 @@
using EnvelopeGenerator.Application.Model;
namespace EnvelopeGenerator.Application.Interfaces.Model;
/// <summary>
///
/// </summary>
public interface IHasReceiverQuery<TReceiverQuery>
where TReceiverQuery : ReceiverQueryBase
{
/// <summary>
///
/// </summary>
public TReceiverQuery Receiver { get; set; }
}
/// <summary>
///
/// </summary>
public interface IHasReceiverQuery
: IHasReceiverQuery<ReceiverQueryBase>
{
}

View File

@ -1,5 +1,4 @@
using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Application.Interfaces.Model;
using EnvelopeGenerator.Extensions;
namespace EnvelopeGenerator.Application.Model;
@ -7,14 +6,14 @@ namespace EnvelopeGenerator.Application.Model;
/// <summary>
///
/// </summary>
public record EnvelopeReceiverQueryBase : EnvelopeReceiverQueryBase<EnvelopeQueryBase, ReceiverQueryBase>, IHasEnvelopeQuery, IHasReceiverQuery;
public record EnvelopeReceiverQueryBase : EnvelopeReceiverQueryBase<EnvelopeQueryBase, ReceiverQueryBase>;
/// <summary>
///
/// </summary>
/// <typeparam name="TEnvelopeQuery"></typeparam>
/// <typeparam name="TReceiverQuery"></typeparam>
public record EnvelopeReceiverQueryBase<TEnvelopeQuery, TReceiverQuery> : IHasEnvelopeQuery<TEnvelopeQuery>, IHasReceiverQuery<TReceiverQuery>
public record EnvelopeReceiverQueryBase<TEnvelopeQuery, TReceiverQuery>
where TEnvelopeQuery : EnvelopeQueryBase, new()
where TReceiverQuery : ReceiverQueryBase, new()
{