1631786ce2
Add push contracts, provider delivery and channel diagnostics. Link email channels to services and document migration and validation. Ref: IT-1074
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using HrynCo.NotificationService.DAL.Abstract.Providers;
|
|
using HrynCo.NotificationService.DAL.Abstract.Repositories;
|
|
using HrynCo.NotificationService.Services.Core;
|
|
using HrynCo.NotificationService.Services.Logging;
|
|
using static HrynCo.NotificationService.Services.Core.ServiceResultHelper;
|
|
|
|
namespace HrynCo.NotificationService.Services.EmailChannels.Create;
|
|
|
|
internal sealed class CreateEmailChannelHandler
|
|
: RequestHandler<CreateEmailChannelCommand, ServiceResult<Guid>>
|
|
{
|
|
private readonly IEmailChannelRepository _channels;
|
|
private readonly INotificationServiceRepository _services;
|
|
|
|
public CreateEmailChannelHandler(
|
|
IContextualSerilogLogger<CreateEmailChannelCommand> logger,
|
|
IEmailChannelRepository channels,
|
|
INotificationServiceRepository services)
|
|
: base(logger)
|
|
{
|
|
_channels = channels;
|
|
_services = services;
|
|
}
|
|
|
|
protected override async Task<ServiceResult<Guid>> DoOnHandle(
|
|
CreateEmailChannelCommand request, CancellationToken cancellationToken)
|
|
{
|
|
if (request.ServiceId == Guid.Empty || await _services.GetAsync(request.ServiceId, cancellationToken) is null)
|
|
return Failure<Guid>("Select an existing service.", ServiceErrorCode.InvalidRequest);
|
|
|
|
var channel = new EmailChannel
|
|
{
|
|
ServiceId = request.ServiceId,
|
|
Priority = request.Priority,
|
|
EmailChannelType = request.ChannelType,
|
|
Settings = request.Settings,
|
|
DailyLimit = request.DailyLimit,
|
|
MonthlyLimit = request.MonthlyLimit,
|
|
WarnThresholdPercent = request.WarnThresholdPercent,
|
|
IsActive = request.IsActive
|
|
};
|
|
|
|
await _channels.AddAsync(channel, cancellationToken);
|
|
|
|
return Success(channel.Id);
|
|
}
|
|
}
|