feat: add RabbitMQ worker, contracts, usage UI in channels screen
- Add HrynCo.NotificationService.Contracts project with SendEmailMessage and NotificationResultMessage - Add SendEmailConsumer (RabbitMQ worker) with reply-to pattern via CorrelationContext.ReplyTo - Add SendEmailHandler owning SMTP send + usage increment as business logic - Add GetChannelUsageSummaryHandler with single DB query via navigation property - Merge usage stats inline into channels list (daily/monthly with progress bars) - Refactor AdminChannelsController.Index to use GetChannelUsageSummaryQuery - Add RabbitMQ service to docker-compose files - Remove dead AdminChannelUsageController, ChannelUsageViewModel, ChannelUsageSummary Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
using HrynCo.NotificationService.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);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
using HrynCo.NotificationService.DAL.Abstract.Providers;
|
||||
using HrynCo.NotificationService.Services.Core;
|
||||
using MediatR;
|
||||
|
||||
namespace HrynCo.NotificationService.Services.EmailChannels.GetUsageSummary;
|
||||
|
||||
public sealed record GetChannelUsageSummaryQuery
|
||||
: IRequest<ServiceResult<IReadOnlyList<ChannelUsageEntry>>>;
|
||||
|
||||
public sealed record ChannelUsageEntry(
|
||||
Guid ChannelId,
|
||||
string ServiceName,
|
||||
string ChannelType,
|
||||
bool IsActive,
|
||||
int Priority,
|
||||
int? DailyLimit,
|
||||
int? MonthlyLimit,
|
||||
int DailySent,
|
||||
int MonthlySent);
|
||||
Reference in New Issue
Block a user