Files
hrynco-notification-service/HrynCo.NotificationService.Worker.Services/EmailProcessing/EmailTemplateService.cs
T
agrynco 81654c0d33 feat(templates): add service language template management
Add normalized service and template catalogs, scoped administration, migration, validation, and regression coverage.

Ref: IT-1601
2026-10-17 22:02:43 +03:00

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}'.");
}
}