Refactor EnvelopeMailService to use MediatR ISender
Replaces IAuthenticator with ISender in EnvelopeMailService, updates the constructor accordingly, and removes unused dependencies. Improves code readability and formatting, cleans up unused usings and redundant code, and aligns with the intended MediatR-based architecture. No functional changes to email sending logic.
This commit is contained in:
@@ -4,7 +4,6 @@ using DigitalData.EmailProfilerDispatcher.Abstraction.DTOs.EmailOut;
|
|||||||
using DigitalData.EmailProfilerDispatcher.Abstraction.Services;
|
using DigitalData.EmailProfilerDispatcher.Abstraction.Services;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using DigitalData.Core.Abstraction.Application.DTO;
|
using DigitalData.Core.Abstraction.Application.DTO;
|
||||||
using EnvelopeGenerator.Domain.Constants;
|
using EnvelopeGenerator.Domain.Constants;
|
||||||
using EnvelopeGenerator.Application.Common.Configurations;
|
using EnvelopeGenerator.Application.Common.Configurations;
|
||||||
@@ -12,6 +11,7 @@ using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver;
|
|||||||
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
|
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiverReadOnly;
|
||||||
using EnvelopeGenerator.Application.Common.Extensions;
|
using EnvelopeGenerator.Application.Common.Extensions;
|
||||||
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
||||||
|
using MediatR;
|
||||||
|
|
||||||
namespace EnvelopeGenerator.Application.Services;
|
namespace EnvelopeGenerator.Application.Services;
|
||||||
|
|
||||||
@@ -21,40 +21,40 @@ namespace EnvelopeGenerator.Application.Services;
|
|||||||
[Obsolete("Use MediatR")]
|
[Obsolete("Use MediatR")]
|
||||||
public class EnvelopeMailService : EmailOutService, IEnvelopeMailService
|
public class EnvelopeMailService : EmailOutService, IEnvelopeMailService
|
||||||
{
|
{
|
||||||
private readonly IEmailTemplateService _tempService;
|
private readonly IEmailTemplateService _tempService;
|
||||||
private readonly IEnvelopeReceiverService _envRcvService;
|
private readonly IEnvelopeReceiverService _envRcvService;
|
||||||
private readonly DispatcherParams _dConfig;
|
private readonly DispatcherParams _dConfig;
|
||||||
private readonly IConfigService _configService;
|
private readonly IConfigService _configService;
|
||||||
private readonly Dictionary<string, string> _placeholders;
|
private readonly Dictionary<string, string> _placeholders;
|
||||||
private readonly IAuthenticator _authenticator;
|
private readonly ISender _sender;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="repository"></param>
|
/// <param name="repository"></param>
|
||||||
/// <param name="mapper"></param>
|
/// <param name="mapper"></param>
|
||||||
/// <param name="tempService"></param>
|
/// <param name="tempService"></param>
|
||||||
/// <param name="envelopeReceiverService"></param>
|
/// <param name="envelopeReceiverService"></param>
|
||||||
/// <param name="dispatcherConfigOptions"></param>
|
/// <param name="dispatcherConfigOptions"></param>
|
||||||
/// <param name="configService"></param>
|
/// <param name="configService"></param>
|
||||||
/// <param name="mailConfig"></param>
|
/// <param name="mailConfig"></param>
|
||||||
/// <param name="authenticator"></param>
|
/// <param name="sender"></param>
|
||||||
public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions<DispatcherParams> dispatcherConfigOptions, IConfigService configService, IOptions<MailParams> mailConfig, IAuthenticator authenticator) : base(repository, mapper)
|
public EnvelopeMailService(IEmailOutRepository repository, IMapper mapper, IEmailTemplateService tempService, IEnvelopeReceiverService envelopeReceiverService, IOptions<DispatcherParams> dispatcherConfigOptions, IConfigService configService, IOptions<MailParams> mailConfig, ISender sender) : base(repository, mapper)
|
||||||
{
|
{
|
||||||
_tempService = tempService;
|
_tempService = tempService;
|
||||||
_envRcvService = envelopeReceiverService;
|
_envRcvService = envelopeReceiverService;
|
||||||
_dConfig = dispatcherConfigOptions.Value;
|
_dConfig = dispatcherConfigOptions.Value;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
_placeholders = new Dictionary<string, string>(mailConfig.Value.Placeholders);
|
_placeholders = new Dictionary<string, string>(mailConfig.Value.Placeholders);
|
||||||
_authenticator = authenticator;
|
_sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, string>> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null)
|
private async Task<Dictionary<string, string>> CreatePlaceholders(string? accessCode = null, EnvelopeReceiverDto? envelopeReceiverDto = null)
|
||||||
{
|
{
|
||||||
if (accessCode is not null)
|
if (accessCode is not null)
|
||||||
_placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode;
|
_placeholders["[DOCUMENT_ACCESS_CODE]"] = accessCode;
|
||||||
|
|
||||||
if(envelopeReceiverDto?.Envelope is not null && envelopeReceiverDto.Receiver is not null)
|
if (envelopeReceiverDto?.Envelope is not null && envelopeReceiverDto.Receiver is not null)
|
||||||
{
|
{
|
||||||
var erId = (envelopeReceiverDto.Envelope.Uuid, envelopeReceiverDto.Receiver.Signature).ToEnvelopeKey();
|
var erId = (envelopeReceiverDto.Envelope.Uuid, envelopeReceiverDto.Receiver.Signature).ToEnvelopeKey();
|
||||||
var sigHost = await _configService.ReadDefaultSignatureHost();
|
var sigHost = await _configService.ReadDefaultSignatureHost();
|
||||||
@@ -64,7 +64,7 @@ private async Task<Dictionary<string, string>> CreatePlaceholders(string? access
|
|||||||
}
|
}
|
||||||
|
|
||||||
return _placeholders;
|
return _placeholders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Dictionary<string, string>> CreatePlaceholders(EnvelopeReceiverReadOnlyDto? readOnlyDto = null)
|
private async Task<Dictionary<string, string>> CreatePlaceholders(EnvelopeReceiverReadOnlyDto? readOnlyDto = null)
|
||||||
{
|
{
|
||||||
@@ -81,13 +81,13 @@ private async Task<Dictionary<string, string>> CreatePlaceholders(string? access
|
|||||||
return _placeholders;
|
return _placeholders;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto"></param>
|
/// <param name="dto"></param>
|
||||||
/// <param name="tempType"></param>
|
/// <param name="tempType"></param>
|
||||||
/// <param name="optionalPlaceholders"></param>
|
/// <param name="optionalPlaceholders"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverDto dto, EmailTemplateType tempType, Dictionary<string, object>? optionalPlaceholders = null)
|
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverDto dto, EmailTemplateType tempType, Dictionary<string, object>? optionalPlaceholders = null)
|
||||||
{
|
{
|
||||||
var tempSerResult = await _tempService.ReadByNameAsync(tempType);
|
var tempSerResult = await _tempService.ReadByNameAsync(tempType);
|
||||||
@@ -112,7 +112,7 @@ private async Task<Dictionary<string, string>> CreatePlaceholders(string? access
|
|||||||
ReminderTypeId = _dConfig.ReminderTypeId,
|
ReminderTypeId = _dConfig.ReminderTypeId,
|
||||||
SendingProfile = _dConfig.SendingProfile,
|
SendingProfile = _dConfig.SendingProfile,
|
||||||
EntityId = null,
|
EntityId = null,
|
||||||
WfId = (int) EnvelopeStatus.MessageAccessCodeSent,
|
WfId = (int)EnvelopeStatus.MessageAccessCodeSent,
|
||||||
WfReference = null,
|
WfReference = null,
|
||||||
AddedWho = _dConfig.AddedWho,
|
AddedWho = _dConfig.AddedWho,
|
||||||
EmailAttmt1 = _dConfig.EmailAttmt1
|
EmailAttmt1 = _dConfig.EmailAttmt1
|
||||||
@@ -132,18 +132,18 @@ private async Task<Dictionary<string, string>> CreatePlaceholders(string? access
|
|||||||
placeholders[oph.Key] = oph.Value.ToString() ?? "NULL";
|
placeholders[oph.Key] = oph.Value.ToString() ?? "NULL";
|
||||||
|
|
||||||
//TODO: remove the requirement to add the models using reflections
|
//TODO: remove the requirement to add the models using reflections
|
||||||
return await CreateWithTemplateAsync(createDto: mail,placeholders: placeholders,
|
return await CreateWithTemplateAsync(createDto: mail, placeholders: placeholders,
|
||||||
dto, dto.Envelope.User!, dto.Envelope);
|
dto, dto.Envelope.User!, dto.Envelope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dto"></param>
|
/// <param name="dto"></param>
|
||||||
/// <param name="optionalPlaceholders"></param>
|
/// <param name="optionalPlaceholders"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto, Dictionary<string, object>? optionalPlaceholders = null)
|
public async Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto, Dictionary<string, object>? optionalPlaceholders = null)
|
||||||
{
|
{
|
||||||
var tempSerResult = await _tempService.ReadByNameAsync(EmailTemplateType.DocumentShared);
|
var tempSerResult = await _tempService.ReadByNameAsync(EmailTemplateType.DocumentShared);
|
||||||
if (tempSerResult.IsFailed)
|
if (tempSerResult.IsFailed)
|
||||||
return tempSerResult.ToFail<int>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"The email cannot send because '{EmailTemplateType.DocumentShared}' template cannot found.");
|
return tempSerResult.ToFail<int>().Notice(LogLevel.Error, Flag.DataIntegrityIssue, $"The email cannot send because '{EmailTemplateType.DocumentShared}' template cannot found.");
|
||||||
@@ -155,7 +155,7 @@ public async Task<DataResult<int>> SendAsync(EnvelopeReceiverReadOnlyDto dto, Di
|
|||||||
EmailSubj = temp.Subject,
|
EmailSubj = temp.Subject,
|
||||||
EmailBody = temp.Body,
|
EmailBody = temp.Body,
|
||||||
//TODO: remove int casting when all
|
//TODO: remove int casting when all
|
||||||
ReferenceId = (int) dto.EnvelopeId, //REFERENCE_ID = ENVELOPE_ID
|
ReferenceId = (int)dto.EnvelopeId, //REFERENCE_ID = ENVELOPE_ID
|
||||||
ReferenceString = dto.Envelope!.Uuid, //REFERENCE_STRING = ENVELOPE_UUID
|
ReferenceString = dto.Envelope!.Uuid, //REFERENCE_STRING = ENVELOPE_UUID
|
||||||
//receiver_name = receiver.name,
|
//receiver_name = receiver.name,
|
||||||
//receiver_access_code = receiver.access_code,
|
//receiver_access_code = receiver.access_code,
|
||||||
|
|||||||
Reference in New Issue
Block a user