diff --git a/EnvelopeGenerator.Application/Common/Notifications/DocSignedNotification.cs b/EnvelopeGenerator.Application/Common/Notifications/DocSignedNotification.cs
index 0a6457c4..051bc638 100644
--- a/EnvelopeGenerator.Application/Common/Notifications/DocSignedNotification.cs
+++ b/EnvelopeGenerator.Application/Common/Notifications/DocSignedNotification.cs
@@ -1,5 +1,6 @@
using EnvelopeGenerator.Application.Dto.EnvelopeReceiver;
using MediatR;
+using System.Dynamic;
namespace EnvelopeGenerator.Application.Common.Notifications;
@@ -9,6 +10,10 @@ namespace EnvelopeGenerator.Application.Common.Notifications;
///
public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeReceiverDto(Original), INotification
{
+ ///
+ ///
+ ///
+ public required ExpandoObject Annotations { get; init; }
}
///
@@ -20,14 +25,17 @@ public static class DocSignedNotificationExtensions
/// Converts an to a .
///
/// The DTO to convert.
+ ///
/// A new instance.
- public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto) => new (dto);
+ public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto, ExpandoObject annotations)
+ => new(dto) { Annotations = annotations };
///
/// Asynchronously converts a to a .
///
/// The task that returns the DTO to convert.
+ ///
/// A task that represents the asynchronous conversion operation.
- public static async Task ToDocSignedNotification(this Task dtoTask)
- => new(await dtoTask);
+ public static async Task ToDocSignedNotification(this Task dtoTask, ExpandoObject annotations)
+ => await dtoTask is EnvelopeReceiverDto dto ? new(dto) { Annotations = annotations } : null;
}
\ No newline at end of file
diff --git a/EnvelopeGenerator.Application/Common/Notifications/Handlers/DocSignedNotificationStatusHandler.cs b/EnvelopeGenerator.Application/Common/Notifications/Handlers/DocSignedNotificationStatusHandler.cs
index 0975a7c1..512ba9c9 100644
--- a/EnvelopeGenerator.Application/Common/Notifications/Handlers/DocSignedNotificationStatusHandler.cs
+++ b/EnvelopeGenerator.Application/Common/Notifications/Handlers/DocSignedNotificationStatusHandler.cs
@@ -1,4 +1,7 @@
-using MediatR;
+using EnvelopeGenerator.Application.DocStatus.Commands;
+using EnvelopeGenerator.Domain.Constants;
+using MediatR;
+using Newtonsoft.Json;
namespace EnvelopeGenerator.Application.Common.Notifications.Handlers;
@@ -7,15 +10,30 @@ namespace EnvelopeGenerator.Application.Common.Notifications.Handlers;
///
public class DocSignedNotificationStatusHandler : INotificationHandler
{
+ private readonly ISender _sender;
+
+ ///
+ ///
+ ///
+ ///
+ public DocSignedNotificationStatusHandler(ISender sender)
+ {
+ _sender = sender;
+ }
+
///
///
///
///
- ///
+ ///
///
- ///
- public Task Handle(DocSignedNotification notification, CancellationToken cancellationToken)
+ public async Task Handle(DocSignedNotification notification, CancellationToken cancel)
{
- throw new NotImplementedException();
+ await _sender.Send(new SaveDocStatusCommand()
+ {
+ Envelope = new() { Id = notification.EnvelopeId },
+ Receiver = new() { Id = notification.ReceiverId},
+ Value = JsonConvert.SerializeObject(notification.Annotations, Format.Json.ForAnnotations)
+ }, cancel);
}
-}
+}
\ No newline at end of file
diff --git a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs
index 039bf948..f12821c0 100644
--- a/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs
+++ b/EnvelopeGenerator.Application/DocStatus/Commands/SaveDocStatusCommand.cs
@@ -14,34 +14,6 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands;
///
public record SaveDocStatusCommand : ModifyDocStatusCommandBase, IRequest;
-///
-///
-///
-public static class Extensions
-{
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static async Task SignDocAsync(this IMediator mediator, string uuid, string signature, string value, CancellationToken cancel = default)
- {
-
- var docStatus = await mediator.Send(new SaveDocStatusCommand()
- {
- Envelope = new() { Uuid = uuid },
- Receiver = new() { Signature = signature },
- Value = value
- }, cancel);
-
- return docStatus?.Id;
- }
-}
-
///
///
///
diff --git a/EnvelopeGenerator.Domain/Constants/Format.cs b/EnvelopeGenerator.Domain/Constants/Format.cs
index 2f5e28af..1f131e5e 100644
--- a/EnvelopeGenerator.Domain/Constants/Format.cs
+++ b/EnvelopeGenerator.Domain/Constants/Format.cs
@@ -14,6 +14,12 @@ namespace EnvelopeGenerator.Domain.Constants
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Include
};
+ public static readonly JsonSerializerSettings ForAnnotations = new JsonSerializerSettings()
+ {
+ ContractResolver = new CamelCasePropertyNamesContractResolver(),
+ Formatting = Formatting.None,
+ NullValueHandling = NullValueHandling.Ignore
+ };
}
#endregion
}
diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs
index 761c3c9b..e22d5d32 100644
--- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs
+++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs
@@ -13,6 +13,8 @@ using System.Dynamic;
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
using EnvelopeGenerator.Application.DocStatus.Commands;
using Newtonsoft.Json;
+using EnvelopeGenerator.Application.Common.Notifications;
+using DigitalData.Core.Exceptions;
namespace EnvelopeGenerator.Web.Controllers;
@@ -64,7 +66,11 @@ public class EnvelopeController : BaseController
if (await _mediator.IsSignedAsync(uuid, signature, cancel))
return Problem(statusCode: 403);
- await _mediator.SignDocAsync(uuid, signature, JsonConvert.SerializeObject(annotations), cancel);
+ var notification = await _mediator.ReadEnvelopeReceiverAsync(envelopeKey, cancel)
+ .ToDocSignedNotification(annotations)
+ ?? throw new NotFoundException("Envelope receiver is not found.");
+
+ await _mediator.Publish(notification, cancel);
EnvelopeReceiver response = await envelopeService.LoadEnvelope(envelopeKey);