using EnvelopeGenerator.Application.Common.Notifications.DocSigned; using EnvelopeGenerator.Application.Histories.Commands; using EnvelopeGenerator.Domain.Constants; using MediatR; using Newtonsoft.Json; namespace EnvelopeGenerator.Application.Common.Notifications.DocSigned.Handlers; /// /// /// public class HistoryHandler : INotificationHandler { private readonly ISender _sender; /// /// /// /// public HistoryHandler(ISender sender) { _sender = sender; } /// /// /// /// /// /// public async Task Handle(DocSignedNotification notification, CancellationToken cancel) { if(notification.Receiver is null) if (notification.Receiver is null) throw new InvalidOperationException($"Receiver information is missing in the notification. DocSignedNotification:\n {JsonConvert.SerializeObject(notification, Format.Json.ForDiagnostics)}"); await _sender.Send(new CreateHistoryCommand() { EnvelopeId = notification.EnvelopeId, UserReference = notification.Receiver.EmailAddress, Status = EnvelopeStatus.DocumentSigned, Comment = JsonConvert.SerializeObject(notification.Annotations, Format.Json.ForAnnotations) }, cancel); } }