Files
hrynco-notification-service/HrynCo.NotificationService.Services/EmailChannels/Create/CreateEmailChannelHandler.cs
T
agrynco 1631786ce2 feat(push): add service-owned firebase channels and delivery
Add push contracts, provider delivery and channel diagnostics. Link email channels to services and document migration and validation.

Ref: IT-1074
2026-10-24 12:31:35 +03:00

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);
}
}