81654c0d33
Add normalized service and template catalogs, scoped administration, migration, validation, and regression coverage. Ref: IT-1601
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
namespace HrynCo.NotificationService.Worker.Services.EmailProcessing;
|
|
|
|
using HrynCo.NotificationService.DAL.Abstract.Repositories;
|
|
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
|
|
|
internal sealed class EmailTemplateService : IEmailTemplateService
|
|
{
|
|
private readonly IEmailTemplateRepository _templateRepository;
|
|
|
|
public EmailTemplateService(IEmailTemplateRepository templateRepository)
|
|
{
|
|
_templateRepository = templateRepository;
|
|
}
|
|
|
|
public async Task<EmailTemplate> GetAsync(
|
|
string serviceName,
|
|
string templateKey,
|
|
string? languageCode,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(languageCode))
|
|
throw new InvalidDataException("LanguageCode is required.");
|
|
|
|
EmailTemplate? template = await _templateRepository.GetAsync(
|
|
serviceName,
|
|
templateKey,
|
|
languageCode,
|
|
cancellationToken);
|
|
|
|
if (template is null)
|
|
{
|
|
string compatibilityCode = languageCode.Trim().ToLowerInvariant();
|
|
if (!string.Equals(languageCode, compatibilityCode, StringComparison.Ordinal))
|
|
template = await _templateRepository.GetAsync(serviceName, templateKey, compatibilityCode, cancellationToken);
|
|
}
|
|
|
|
return template
|
|
?? throw new InvalidOperationException(
|
|
$"Template not found: service='{serviceName}' key='{templateKey}' language='{languageCode}'.");
|
|
}
|
|
}
|