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.
This commit is contained in:
Anatolii Grynchuk
2026-05-13 02:08:43 +03:00
parent b4d8497ea7
commit 50828d23ec
32 changed files with 276 additions and 186 deletions
@@ -1,11 +1,11 @@
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.DAL.EF.Core;
using HrynCo.NotificationService.DAL.EF.Core;
using HrynCo.NotificationService.DAL.EF.Entities;
using Microsoft.EntityFrameworkCore;
namespace HrynCo.NotificationService.DAL.EF.Repositories;
internal sealed class EmailChannelUsageRepository : EfRepository<NotificationDbContext, EmailChannelUsageEntity>, IEmailChannelUsageRepository
internal sealed class EmailChannelUsageRepository : NotificationBaseRepository<EmailChannelUsageEntity>, IEmailChannelUsageRepository
{
public EmailChannelUsageRepository(NotificationDbContext dbContext) : base(dbContext)
{
@@ -13,7 +13,8 @@ internal sealed class EmailChannelUsageRepository : EfRepository<NotificationDbC
public async Task<int> GetDailyCountAsync(Guid providerId, DateOnly date, CancellationToken ct = default)
{
EmailChannelUsageEntity? entity = await DbSet
EmailChannelUsageEntity? entity = await EfRepository.Get()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ProviderId == providerId && x.Date == date, ct);
return entity?.SentCount ?? 0;
@@ -21,7 +22,7 @@ internal sealed class EmailChannelUsageRepository : EfRepository<NotificationDbC
public async Task<int> GetMonthlyCountAsync(Guid providerId, int year, int month, CancellationToken ct = default)
{
return await DbSet
return await EfRepository.Get()
.Where(x => x.ProviderId == providerId
&& x.Date.Year == year
&& x.Date.Month == month)
@@ -30,15 +31,16 @@ internal sealed class EmailChannelUsageRepository : EfRepository<NotificationDbC
public async Task IncrementUsageAsync(Guid providerId, DateOnly date, CancellationToken ct = default)
{
EmailChannelUsageEntity? entity = await DbSet
EmailChannelUsageEntity? entity = await EfRepository.Get()
.AsNoTracking()
.FirstOrDefaultAsync(x => x.ProviderId == providerId && x.Date == date, ct);
if (entity is null)
await AddAsync(new EmailChannelUsageEntity { ProviderId = providerId, Date = date, SentCount = 1 }, ct);
await EfRepository.AddAsync(new EmailChannelUsageEntity { ProviderId = providerId, Date = date, SentCount = 1 });
else
{
entity.SentCount++;
Update(entity);
await EfRepository.UpdateAsync(entity);
}
}
}