feat(EnvelopeReceiverService): SendSmsAsync hinzugefügt, um SMS an den Benutzer über die Umschlag-Empfänger-ID mithilfe des Messaging-Services zu senden.
This commit is contained in:
@@ -9,6 +9,7 @@ using EnvelopeGenerator.Infrastructure.Contracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using EnvelopeGenerator.Extensions;
|
||||
using EnvelopeGenerator.Application.DTOs.Messaging;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Services
|
||||
{
|
||||
@@ -16,10 +17,13 @@ namespace EnvelopeGenerator.Application.Services
|
||||
{
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
|
||||
public EnvelopeReceiverService(IEnvelopeReceiverRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper)
|
||||
private readonly IMessagingService _messagingService;
|
||||
|
||||
public EnvelopeReceiverService(IEnvelopeReceiverRepository repository, IStringLocalizer<Resource> localizer, IMapper mapper, IMessagingService messagingService)
|
||||
: base(repository, mapper)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_messagingService = messagingService;
|
||||
}
|
||||
|
||||
public async Task<DataResult<IEnumerable<EnvelopeReceiverDto>>> ReadBySignatureAsync(string signature, bool withEnvelope = false, bool withReceiver = true)
|
||||
@@ -135,5 +139,31 @@ namespace EnvelopeGenerator.Application.Services
|
||||
var er = await _repository.ReadLastByReceiver(mail);
|
||||
return er is null ? Result.Fail<string?>().Notice(LogLevel.None, Flag.NotFound) : Result.Success(er.Name);
|
||||
}
|
||||
|
||||
public async Task<DataResult<SmsResponse>> SendSmsAsync(string envelopeReceiverId, string message)
|
||||
{
|
||||
(string? uuid, string? signature) = envelopeReceiverId.DecodeEnvelopeReceiverId();
|
||||
|
||||
if (uuid is null || signature is null)
|
||||
return Result.Fail<SmsResponse>()
|
||||
.Message(_localizer[Key.WrongEnvelopeReceiverId])
|
||||
.Notice(LogLevel.Warning, (uuid, signature).ToTitle())
|
||||
.Notice(LogLevel.Warning, EnvelopeFlag.WrongEnvelopeReceiverId)
|
||||
.Notice(LogLevel.Warning, Flag.PossibleSecurityBreach);
|
||||
|
||||
var env_rcv = await _repository.ReadByUuidSignatureAsync(uuid: uuid, signature: signature, withEnvelope: false, withReceiver: false);
|
||||
if (env_rcv is null)
|
||||
return Result.Fail<SmsResponse>()
|
||||
.Message(Key.EnvelopeReceiverNotFound);
|
||||
|
||||
if (env_rcv.PhoneNumber is null)
|
||||
return Result.Fail<SmsResponse>()
|
||||
.Message(Key.PhoneNumberNonexists)
|
||||
.Notice(LogLevel.Error, Flag.NotFound, $"An attempt was made to send sms to the user whose phone number is null. Envelope recipient ID is {envelopeReceiverId}, UUID is {uuid} and signature is {signature}.");
|
||||
|
||||
var res = await _messagingService.SendSmsAsync(recipient: env_rcv.PhoneNumber, message: message);
|
||||
|
||||
return Result.Success(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user