50828d23ec
- 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.
33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using HrynCo.NotificationService.DAL.Abstract.Repositories;
|
|
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
|
using HrynCo.NotificationService.Services.Core;
|
|
using HrynCo.NotificationService.Services.Logging;
|
|
using static HrynCo.NotificationService.Services.Core.ServiceResultHelper;
|
|
|
|
namespace HrynCo.NotificationService.Services.EmailTemplates.Get;
|
|
|
|
internal sealed class GetEmailTemplateHandler
|
|
: RequestHandler<GetEmailTemplateQuery, ServiceResult<EmailTemplate>>
|
|
{
|
|
private readonly IEmailTemplateRepository _templates;
|
|
|
|
public GetEmailTemplateHandler(
|
|
IContextualSerilogLogger<GetEmailTemplateQuery> logger,
|
|
IEmailTemplateRepository templates)
|
|
: base(logger)
|
|
{
|
|
_templates = templates;
|
|
}
|
|
|
|
protected override async Task<ServiceResult<EmailTemplate>> DoOnHandle(
|
|
GetEmailTemplateQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var template = await _templates.GetAsync(
|
|
request.ServiceName, request.Key, request.LanguageCode, cancellationToken);
|
|
|
|
return template is null
|
|
? Failure<EmailTemplate>("Template not found.", ServiceErrorCode.NotFound)
|
|
: Success(template);
|
|
}
|
|
}
|