Files
hrynco-notification-service/HrynCo.NotificationService.Services/EmailChannels/GetUsageSummary/GetChannelUsageSummaryHandler.cs
T
Anatolii Grynchuk 50828d23ec refactor: replace internal UnitOfWork with NotificationUnitOfWork and NotificationBaseRepository
- Consolidate unit of work implementation with NotificationUnitOfWork.
- Refactor repositories to use NotificationBaseRepository for consistency.
- Simplify request handlers by removing IUnitOfWork dependency.
- Update related tests and service registration.
2026-05-13 02:08:43 +03:00

44 lines
1.7 KiB
C#

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,
IEmailChannelRepository channelsRepository)
: base(logger)
{
_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);
}
}