25fb48ccf0
- Extract email template handling, rendering, and sending code into `Worker.Services` project. - Introduce `EmailTemplateService`, `EmailTemplateRenderingService`, and `SendEmailService`. - Simplify consumer logic by delegating to scoped services. - Update project dependencies and package references accordingly.
32 lines
1.2 KiB
C#
32 lines
1.2 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)
|
|
{
|
|
var lang = string.IsNullOrWhiteSpace(languageCode) ? "en" : languageCode;
|
|
var template = await _templateRepository.GetAsync(serviceName, templateKey, lang, cancellationToken);
|
|
|
|
if (template is null && lang != "en")
|
|
template = await _templateRepository.GetAsync(serviceName, templateKey, "en", cancellationToken);
|
|
|
|
return template
|
|
?? throw new InvalidOperationException(
|
|
$"Template not found: service='{serviceName}' key='{templateKey}' language='{lang}'.");
|
|
}
|
|
}
|