Refactor DocSignedNotification for better encapsulation
Refactored `DocSignedNotification` to remove inheritance from `EnvelopeReceiverDto` and introduced a required `EnvelopeReceiver` property. Updated all usages across the codebase to align with the new structure, including controllers, handlers, and tests. - Improved encapsulation and reduced coupling by making dependencies explicit. - Updated `AnnotationController`, `DocStatusHandler`, `HistoryHandler`, and `SendSignedMailHandler` to use the `EnvelopeReceiver` property. - Adjusted `DocSignedNotificationTests` to reflect the new instantiation pattern. - Updated XML documentation and ensured consistent access to `EnvelopeReceiver` properties like `EnvelopeId`, `ReceiverId`, and `EmailAddress`.
This commit is contained in:
@@ -75,7 +75,7 @@ public class AnnotationController : ControllerBase
|
|||||||
|
|
||||||
var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
|
var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
|
||||||
var docSignedNotification = envelopeReceiverDto is not null
|
var docSignedNotification = envelopeReceiverDto is not null
|
||||||
? new DocSignedNotification(envelopeReceiverDto) { PsPdfKitAnnotation = psPdfKitAnnotation }
|
? new DocSignedNotification { EnvelopeReceiver = envelopeReceiverDto, PsPdfKitAnnotation = psPdfKitAnnotation }
|
||||||
: throw new NotFoundException("Envelope receiver is not found.");
|
: throw new NotFoundException("Envelope receiver is not found.");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -86,8 +86,8 @@ public class AnnotationController : ControllerBase
|
|||||||
{
|
{
|
||||||
await _mediator.Publish(new RemoveSignatureNotification()
|
await _mediator.Publish(new RemoveSignatureNotification()
|
||||||
{
|
{
|
||||||
EnvelopeId = docSignedNotification.EnvelopeId,
|
EnvelopeId = docSignedNotification.EnvelopeReceiver.EnvelopeId,
|
||||||
ReceiverId = docSignedNotification.ReceiverId
|
ReceiverId = docSignedNotification.EnvelopeReceiver.ReceiverId
|
||||||
}, cancel);
|
}, cancel);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,29 @@ namespace EnvelopeGenerator.Application.Common.Notifications.DocSigned;
|
|||||||
public record PsPdfKitAnnotation(ExpandoObject Instant, IEnumerable<AnnotationCreateDto> Structured);
|
public record PsPdfKitAnnotation(ExpandoObject Instant, IEnumerable<AnnotationCreateDto> Structured);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Notification raised when a document is signed by a receiver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Original"></param>
|
public record DocSignedNotification : INotification, ISendMailNotification
|
||||||
public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeReceiverDto(Original), INotification, ISendMailNotification
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// The envelope receiver information.
|
||||||
|
/// </summary>
|
||||||
|
public required EnvelopeReceiverDto EnvelopeReceiver { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The PSPDFKit annotation data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PsPdfKitAnnotation? PsPdfKitAnnotation { get; init; }
|
public PsPdfKitAnnotation? PsPdfKitAnnotation { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets the email template type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EmailTemplateType TemplateType => EmailTemplateType.DocumentSigned;
|
public EmailTemplateType TemplateType => EmailTemplateType.DocumentSigned;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Gets the email address of the receiver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string EmailAddress => Receiver?.EmailAddress
|
public string EmailAddress => EnvelopeReceiver.Receiver?.EmailAddress
|
||||||
?? throw new InvalidOperationException($"Receiver is null." +
|
?? throw new InvalidOperationException($"Receiver is null." +
|
||||||
$"DocSignedNotification:\n{this.ToJson(Format.Json.ForDiagnostics)}");
|
$"DocSignedNotification:\n{this.ToJson(Format.Json.ForDiagnostics)}");
|
||||||
}
|
}
|
||||||
@@ -31,8 +31,8 @@ public class DocStatusHandler : INotificationHandler<DocSignedNotification>
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task Handle(DocSignedNotification notification, CancellationToken cancel) => _sender.Send(new CreateDocStatusCommand()
|
public Task Handle(DocSignedNotification notification, CancellationToken cancel) => _sender.Send(new CreateDocStatusCommand()
|
||||||
{
|
{
|
||||||
EnvelopeId = notification.EnvelopeId,
|
EnvelopeId = notification.EnvelopeReceiver.EnvelopeId,
|
||||||
ReceiverId = notification.ReceiverId,
|
ReceiverId = notification.EnvelopeReceiver.ReceiverId,
|
||||||
Value = notification.PsPdfKitAnnotation is PsPdfKitAnnotation annot
|
Value = notification.PsPdfKitAnnotation is PsPdfKitAnnotation annot
|
||||||
? JsonSerializer.Serialize(annot.Instant, Format.Json.ForAnnotations)
|
? JsonSerializer.Serialize(annot.Instant, Format.Json.ForAnnotations)
|
||||||
: BlankAnnotationJson
|
: BlankAnnotationJson
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ public class HistoryHandler : INotificationHandler<DocSignedNotification>
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task Handle(DocSignedNotification notification, CancellationToken cancel)
|
public async Task Handle(DocSignedNotification notification, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
if (notification.Receiver is null)
|
if (notification.EnvelopeReceiver.Receiver is null)
|
||||||
throw new InvalidOperationException($"Receiver information is missing in the notification. DocSignedNotification:\n {notification.ToJson(Format.Json.ForDiagnostics)}");
|
throw new InvalidOperationException($"Receiver information is missing in the notification. DocSignedNotification:\n {notification.ToJson(Format.Json.ForDiagnostics)}");
|
||||||
|
|
||||||
await _sender.Send(new CreateHistoryCommand()
|
await _sender.Send(new CreateHistoryCommand()
|
||||||
{
|
{
|
||||||
EnvelopeId = notification.EnvelopeId,
|
EnvelopeId = notification.EnvelopeReceiver.EnvelopeId,
|
||||||
UserReference = notification.Receiver.EmailAddress,
|
UserReference = notification.EnvelopeReceiver.Receiver.EmailAddress,
|
||||||
Status = EnvelopeStatus.DocumentSigned,
|
Status = EnvelopeStatus.DocumentSigned,
|
||||||
}, cancel);
|
}, cancel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class SendSignedMailHandler : SendMailHandler<DocSignedNotification>
|
|||||||
protected override void ConfigureEmailOut(DocSignedNotification notification, EmailOut emailOut)
|
protected override void ConfigureEmailOut(DocSignedNotification notification, EmailOut emailOut)
|
||||||
{
|
{
|
||||||
emailOut.ReferenceString = notification.EmailAddress;
|
emailOut.ReferenceString = notification.EmailAddress;
|
||||||
emailOut.ReferenceId = notification.ReceiverId;
|
emailOut.ReferenceId = notification.EnvelopeReceiver.ReceiverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -42,11 +42,11 @@ public class SendSignedMailHandler : SendMailHandler<DocSignedNotification>
|
|||||||
{
|
{
|
||||||
var placeHolders = new Dictionary<string, string>()
|
var placeHolders = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
{ "[NAME_RECEIVER]", notification.Name ?? string.Empty },
|
{ "[NAME_RECEIVER]", notification.EnvelopeReceiver.Name ?? string.Empty },
|
||||||
{ "[DOCUMENT_TITLE]", notification.Envelope?.Title ?? string.Empty },
|
{ "[DOCUMENT_TITLE]", notification.EnvelopeReceiver.Envelope?.Title ?? string.Empty },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notification.Envelope.IsReadAndConfirm())
|
if (notification.EnvelopeReceiver.Envelope.IsReadAndConfirm())
|
||||||
{
|
{
|
||||||
placeHolders["[SIGNATURE_TYPE]"] = "Lesen und bestätigen";
|
placeHolders["[SIGNATURE_TYPE]"] = "Lesen und bestätigen";
|
||||||
placeHolders["[DOCUMENT_PROCESS]"] = string.Empty;
|
placeHolders["[DOCUMENT_PROCESS]"] = string.Empty;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class DocSignedNotificationTests : TestBase
|
|||||||
|
|
||||||
var annots = Services.GetRequiredService<PsPdfKitAnnotation>();
|
var annots = Services.GetRequiredService<PsPdfKitAnnotation>();
|
||||||
|
|
||||||
var docSignedNtf = new DocSignedNotification(envRcvDto) { PsPdfKitAnnotation = annots };
|
var docSignedNtf = new DocSignedNotification { EnvelopeReceiver = envRcvDto, PsPdfKitAnnotation = annots };
|
||||||
|
|
||||||
var sendSignedMailHandler = Host.Services.GetRequiredService<SendSignedMailHandler>();
|
var sendSignedMailHandler = Host.Services.GetRequiredService<SendSignedMailHandler>();
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class AnnotationController : ControllerBase
|
|||||||
|
|
||||||
var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
|
var envelopeReceiverDto = await _mediator.ReadEnvelopeReceiverAsync(uuid, signature, cancel);
|
||||||
var docSignedNotification = envelopeReceiverDto is not null
|
var docSignedNotification = envelopeReceiverDto is not null
|
||||||
? new DocSignedNotification(envelopeReceiverDto) { PsPdfKitAnnotation = psPdfKitAnnotation }
|
? new DocSignedNotification { EnvelopeReceiver = envelopeReceiverDto, PsPdfKitAnnotation = psPdfKitAnnotation }
|
||||||
: throw new NotFoundException("Envelope receiver is not found.");
|
: throw new NotFoundException("Envelope receiver is not found.");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -83,8 +83,8 @@ public class AnnotationController : ControllerBase
|
|||||||
{
|
{
|
||||||
await _mediator.Publish(new RemoveSignatureNotification()
|
await _mediator.Publish(new RemoveSignatureNotification()
|
||||||
{
|
{
|
||||||
EnvelopeId = docSignedNotification.EnvelopeId,
|
EnvelopeId = docSignedNotification.EnvelopeReceiver.EnvelopeId,
|
||||||
ReceiverId = docSignedNotification.ReceiverId
|
ReceiverId = docSignedNotification.EnvelopeReceiver.ReceiverId
|
||||||
}, cancel);
|
}, cancel);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user