refactor(ModifyDocStatusCommandBase): add EnvelopeId and ReceiverId properties
This commit is contained in:
parent
83ff3da795
commit
6b89b9bbf2
@ -3,10 +3,22 @@ using Microsoft.Extensions.Caching.Memory;
|
|||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Common.Extensions;
|
namespace EnvelopeGenerator.Application.Common.Extensions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
public static class MemoryCacheExtensions
|
public static class MemoryCacheExtensions
|
||||||
{
|
{
|
||||||
private static readonly Guid BaseId = Guid.NewGuid();
|
private static readonly Guid BaseId = Guid.NewGuid();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEnum"></typeparam>
|
||||||
|
/// <param name="memoryCache"></param>
|
||||||
|
/// <param name="key"></param>
|
||||||
|
/// <param name="ignores"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="InvalidOperationException"></exception>
|
||||||
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params object[] ignores)
|
public static IDictionary<string, int> GetEnumAsDictionary<TEnum>(this IMemoryCache memoryCache, string key = "", params object[] ignores)
|
||||||
where TEnum : Enum
|
where TEnum : Enum
|
||||||
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName + key, _ =>
|
=> memoryCache.GetOrCreate(BaseId + typeof(TEnum).FullName + key, _ =>
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using DigitalData.Core.Exceptions;
|
using DigitalData.Core.Exceptions;
|
||||||
using EnvelopeGenerator.Application.Common.Extensions;
|
using EnvelopeGenerator.Application.Common.Extensions;
|
||||||
using EnvelopeGenerator.Application.Common.Query;
|
using EnvelopeGenerator.Application.Common.Query;
|
||||||
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
using EnvelopeGenerator.Domain.Interfaces;
|
using EnvelopeGenerator.Domain.Interfaces;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Common.Extensions;
|
namespace EnvelopeGenerator.Application.Common.Extensions;
|
||||||
@ -34,6 +35,28 @@ public static class QueryExtensions
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="root"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="notnull"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="BadRequestException"></exception>
|
||||||
|
public static IQueryable<Envelope> Where(this IQueryable<Envelope> root, EnvelopeQueryBase query, bool notnull = true)
|
||||||
|
{
|
||||||
|
if (query.Id is not null)
|
||||||
|
root = root.Where(e => e.Id == query.Id);
|
||||||
|
else if (query.Uuid is not null)
|
||||||
|
root = root.Where(e => e.Uuid == query.Uuid);
|
||||||
|
else if (notnull)
|
||||||
|
throw new BadRequestException(
|
||||||
|
"Either Envelope Id or Envelope Uuid must be provided in the query."
|
||||||
|
);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -60,6 +83,30 @@ public static class QueryExtensions
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="root"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="notnull"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="BadRequestException"></exception>
|
||||||
|
public static IQueryable<Receiver> Where(this IQueryable<Receiver> root, ReceiverQueryBase query, bool notnull = true)
|
||||||
|
{
|
||||||
|
if (query.Id is not null)
|
||||||
|
root = root.Where(e => e.Id == query.Id);
|
||||||
|
else if (query.EmailAddress is not null)
|
||||||
|
root = root.Where(e => e.EmailAddress == query.EmailAddress);
|
||||||
|
else if (query.Signature is not null)
|
||||||
|
root = root.Where(e => e.Signature == query.Signature);
|
||||||
|
else if (notnull)
|
||||||
|
throw new BadRequestException(
|
||||||
|
"Receiver must have at least one identifier (Id, EmailAddress, or Signature)."
|
||||||
|
);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
using DigitalData.Core.Abstraction.Application.Repository;
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
using DigitalData.EmailProfilerDispatcher.Abstraction.Entities;
|
||||||
using EnvelopeGenerator.Application.Common.Configurations;
|
using EnvelopeGenerator.Application.Common.Configurations;
|
||||||
using EnvelopeGenerator.Application.Common.Notifications;
|
|
||||||
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
|
|
||||||
using EnvelopeGenerator.Domain.Entities;
|
using EnvelopeGenerator.Domain.Entities;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
|||||||
@ -9,12 +9,12 @@ public record ReceiverQueryBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ID des Empfängers
|
/// ID des Empfängers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual int? Id { get; init; }
|
public virtual int? Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// E-Mail Adresse des Empfängers
|
/// E-Mail Adresse des Empfängers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual string? EmailAddress { get; init; }
|
public virtual string? EmailAddress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eindeutige Signatur des Empfängers
|
/// Eindeutige Signatur des Empfängers
|
||||||
|
|||||||
@ -8,6 +8,21 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public record ModifyDocStatusCommandBase : EnvelopeReceiverQueryBase
|
public record ModifyDocStatusCommandBase : EnvelopeReceiverQueryBase
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public int? EnvelopeId => Envelope.Id;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public int? ReceiverId => Receiver.Id;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public override ReceiverQueryBase Receiver { get => base.Receiver; set => base.Receiver = value; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current status code.
|
/// Gets the current status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -23,15 +23,23 @@ public class SaveDocStatusCommandHandler : IRequestHandler<SaveDocStatusCommand,
|
|||||||
|
|
||||||
private readonly IRepository<DocumentStatus> _repo;
|
private readonly IRepository<DocumentStatus> _repo;
|
||||||
|
|
||||||
|
private readonly IRepository<Envelope> _envRepo;
|
||||||
|
|
||||||
|
private readonly IRepository<Receiver> _rcvRepo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mapper"></param>
|
/// <param name="mapper"></param>
|
||||||
/// <param name="repo"></param>
|
/// <param name="repo"></param>
|
||||||
public SaveDocStatusCommandHandler(IMapper mapper, IRepository<DocumentStatus> repo)
|
/// <param name="rcvRepo"></param>
|
||||||
|
/// <param name="envRepo"></param>
|
||||||
|
public SaveDocStatusCommandHandler(IMapper mapper, IRepository<DocumentStatus> repo, IRepository<Receiver> rcvRepo, IRepository<Envelope> envRepo)
|
||||||
{
|
{
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
_rcvRepo = rcvRepo;
|
||||||
|
_envRepo = envRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -45,6 +53,12 @@ public class SaveDocStatusCommandHandler : IRequestHandler<SaveDocStatusCommand,
|
|||||||
// ceck if exists
|
// ceck if exists
|
||||||
bool isExists = await _repo.ReadOnly().Where(request).AnyAsync(cancel);
|
bool isExists = await _repo.ReadOnly().Where(request).AnyAsync(cancel);
|
||||||
|
|
||||||
|
var env = await _envRepo.ReadOnly().Where(request.Envelope).FirstAsync(cancel);
|
||||||
|
var rcv = await _rcvRepo.ReadOnly().Where(request.Receiver).FirstAsync(cancel);
|
||||||
|
|
||||||
|
request.Envelope.Id = env.Id;
|
||||||
|
request.Receiver.Id = rcv.Id;
|
||||||
|
|
||||||
if (isExists)
|
if (isExists)
|
||||||
{
|
{
|
||||||
var uReq = request.To<UpdateDocStatusCommand>();
|
var uReq = request.To<UpdateDocStatusCommand>();
|
||||||
|
|||||||
@ -14,7 +14,12 @@ public class MappingProfile : Profile
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<CreateDocStatusCommand, DocumentStatus>();
|
CreateMap<CreateDocStatusCommand, DocumentStatus>()
|
||||||
CreateMap<UpdateDocStatusCommand, DocumentStatus>();
|
.ForMember(dest => dest.Envelope, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.Receiver, opt => opt.Ignore());
|
||||||
|
|
||||||
|
CreateMap<UpdateDocStatusCommand, DocumentStatus>()
|
||||||
|
.ForMember(dest => dest.Envelope, opt => opt.Ignore())
|
||||||
|
.ForMember(dest => dest.Receiver, opt => opt.Ignore());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ public class ReadEnvelopeReceiverQueryHandler : IRequestHandler<ReadEnvelopeRece
|
|||||||
/// <exception cref="BadRequestException"></exception>
|
/// <exception cref="BadRequestException"></exception>
|
||||||
public async Task<IEnumerable<EnvelopeReceiverDto>> Handle(ReadEnvelopeReceiverQuery request, CancellationToken cancel)
|
public async Task<IEnumerable<EnvelopeReceiverDto>> Handle(ReadEnvelopeReceiverQuery request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var q = _repo.Read().Where(request, notnull: false);
|
var q = _repo.ReadOnly().Where(request, notnull: false);
|
||||||
|
|
||||||
if (request.Envelope.Status is not null)
|
if (request.Envelope.Status is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -68,6 +68,6 @@ public class ReceiverAlreadySignedQueryHandler : IRequestHandler<ReceiverAlready
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<bool> Handle(ReceiverAlreadySignedQuery request, CancellationToken cancel = default)
|
public async Task<bool> Handle(ReceiverAlreadySignedQuery request, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
return await _repo.Read().Where(request).Where(h => h.Status == EnvelopeStatus.DocumentSigned).AnyAsync(cancel);
|
return await _repo.ReadOnly().Where(request).Where(h => h.Status == EnvelopeStatus.DocumentSigned).AnyAsync(cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user