Files
hrynco-notification-service/HrynCo.NotificationService.Services/EmailChannels/GetUsageSummary/GetChannelUsageSummaryHandler.cs
T
Anatolii Grynchuk ee4c988a0d refactor: replace local dal abstractions with hrynco-ef packages
Remove duplicate IEntity, Entity, ITransaction, IUnitOfWork, EfRepository,
EfUnitOfWork, EfTransactionAdapter — now consumed from HrynCo.DAL.Abstract
and HrynCo.DAL.EF packages (1.0.1).

Ref: IT-0
2026-05-05 20:39:06 +03:00

46 lines
1.8 KiB
C#

using HrynCo.DAL.Abstract;
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.GetUsageSummary;
internal sealed class GetChannelUsageSummaryHandler
: RequestHandler<GetChannelUsageSummaryQuery, ServiceResult<IReadOnlyList<ChannelUsageEntry>>>
{
private readonly IEmailChannelRepository _channelsRepository;
public GetChannelUsageSummaryHandler(
IContextualSerilogLogger<GetChannelUsageSummaryQuery> logger,
IUnitOfWork unitOfWork,
IEmailChannelRepository channelsRepository)
: base(logger, unitOfWork)
{
_channelsRepository = channelsRepository;
}
protected override async Task<ServiceResult<IReadOnlyList<ChannelUsageEntry>>> DoOnHandle(
GetChannelUsageSummaryQuery request, CancellationToken cancellationToken)
{
var today = DateOnly.FromDateTime(DateTime.UtcNow);
var rows = await _channelsRepository.GetAllWithUsageSummaryAsync(today, cancellationToken);
var entries = rows
.Select(r => new ChannelUsageEntry(
ChannelId: r.Channel.Id,
ServiceName: r.Channel.ServiceName,
ChannelType: r.Channel.EmailChannelType.ToString(),
IsActive: r.Channel.IsActive,
Priority: r.Channel.Priority,
DailyLimit: r.Channel.DailyLimit,
MonthlyLimit: r.Channel.MonthlyLimit,
DailySent: r.DailySent,
MonthlySent: r.MonthlySent))
.ToList();
return Success<IReadOnlyList<ChannelUsageEntry>>(entries);
}
}