add DocSignedNotificationStatusHandler and implement the natification into EnveloepControler
This commit is contained in:
parent
aafed0f4f4
commit
fb5d2110bd
@ -1,5 +1,6 @@
|
|||||||
using EnvelopeGenerator.Application.Dto.EnvelopeReceiver;
|
using EnvelopeGenerator.Application.Dto.EnvelopeReceiver;
|
||||||
using MediatR;
|
using MediatR;
|
||||||
|
using System.Dynamic;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Common.Notifications;
|
namespace EnvelopeGenerator.Application.Common.Notifications;
|
||||||
|
|
||||||
@ -9,6 +10,10 @@ namespace EnvelopeGenerator.Application.Common.Notifications;
|
|||||||
/// <param name="Original"></param>
|
/// <param name="Original"></param>
|
||||||
public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeReceiverDto(Original), INotification
|
public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeReceiverDto(Original), INotification
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public required ExpandoObject Annotations { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -20,14 +25,17 @@ public static class DocSignedNotificationExtensions
|
|||||||
/// Converts an <see cref="EnvelopeReceiverDto"/> to a <see cref="DocSignedNotification"/>.
|
/// Converts an <see cref="EnvelopeReceiverDto"/> to a <see cref="DocSignedNotification"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto">The DTO to convert.</param>
|
/// <param name="dto">The DTO to convert.</param>
|
||||||
|
/// <param name="annotations"></param>
|
||||||
/// <returns>A new <see cref="DocSignedNotification"/> instance.</returns>
|
/// <returns>A new <see cref="DocSignedNotification"/> instance.</returns>
|
||||||
public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto) => new (dto);
|
public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto, ExpandoObject annotations)
|
||||||
|
=> new(dto) { Annotations = annotations };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asynchronously converts a <see cref="Task{EnvelopeReceiverDto}"/> to a <see cref="DocSignedNotification"/>.
|
/// Asynchronously converts a <see cref="Task{EnvelopeReceiverDto}"/> to a <see cref="DocSignedNotification"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dtoTask">The task that returns the DTO to convert.</param>
|
/// <param name="dtoTask">The task that returns the DTO to convert.</param>
|
||||||
|
/// <param name="annotations"></param>
|
||||||
/// <returns>A task that represents the asynchronous conversion operation.</returns>
|
/// <returns>A task that represents the asynchronous conversion operation.</returns>
|
||||||
public static async Task<DocSignedNotification> ToDocSignedNotification(this Task<EnvelopeReceiverDto> dtoTask)
|
public static async Task<DocSignedNotification?> ToDocSignedNotification(this Task<EnvelopeReceiverDto?> dtoTask, ExpandoObject annotations)
|
||||||
=> new(await dtoTask);
|
=> await dtoTask is EnvelopeReceiverDto dto ? new(dto) { Annotations = annotations } : null;
|
||||||
}
|
}
|
||||||
@ -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;
|
namespace EnvelopeGenerator.Application.Common.Notifications.Handlers;
|
||||||
|
|
||||||
@ -7,15 +10,30 @@ namespace EnvelopeGenerator.Application.Common.Notifications.Handlers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class DocSignedNotificationStatusHandler : INotificationHandler<DocSignedNotification>
|
public class DocSignedNotificationStatusHandler : INotificationHandler<DocSignedNotification>
|
||||||
{
|
{
|
||||||
|
private readonly ISender _sender;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
public DocSignedNotificationStatusHandler(ISender sender)
|
||||||
|
{
|
||||||
|
_sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="notification"></param>
|
/// <param name="notification"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancel"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="NotImplementedException"></exception>
|
public async Task Handle(DocSignedNotification notification, CancellationToken cancel)
|
||||||
public Task Handle(DocSignedNotification notification, CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -14,34 +14,6 @@ namespace EnvelopeGenerator.Application.DocStatus.Commands;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public record SaveDocStatusCommand : ModifyDocStatusCommandBase, IRequest<DocumentStatusDto?>;
|
public record SaveDocStatusCommand : ModifyDocStatusCommandBase, IRequest<DocumentStatusDto?>;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public static class Extensions
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="mediator"></param>
|
|
||||||
/// <param name="uuid"></param>
|
|
||||||
/// <param name="signature"></param>
|
|
||||||
/// <param name="value"></param>
|
|
||||||
/// <param name="cancel"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static async Task<int?> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -14,6 +14,12 @@ namespace EnvelopeGenerator.Domain.Constants
|
|||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Include
|
NullValueHandling = NullValueHandling.Include
|
||||||
};
|
};
|
||||||
|
public static readonly JsonSerializerSettings ForAnnotations = new JsonSerializerSettings()
|
||||||
|
{
|
||||||
|
ContractResolver = new CamelCasePropertyNamesContractResolver(),
|
||||||
|
Formatting = Formatting.None,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,8 @@ using System.Dynamic;
|
|||||||
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Queries;
|
||||||
using EnvelopeGenerator.Application.DocStatus.Commands;
|
using EnvelopeGenerator.Application.DocStatus.Commands;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using EnvelopeGenerator.Application.Common.Notifications;
|
||||||
|
using DigitalData.Core.Exceptions;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Web.Controllers;
|
namespace EnvelopeGenerator.Web.Controllers;
|
||||||
|
|
||||||
@ -64,7 +66,11 @@ public class EnvelopeController : BaseController
|
|||||||
if (await _mediator.IsSignedAsync(uuid, signature, cancel))
|
if (await _mediator.IsSignedAsync(uuid, signature, cancel))
|
||||||
return Problem(statusCode: 403);
|
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);
|
EnvelopeReceiver response = await envelopeService.LoadEnvelope(envelopeKey);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user