feat(templates): add service language template management

Add normalized service and template catalogs, scoped administration, migration, validation, and regression coverage.

Ref: IT-1601
This commit is contained in:
2026-10-17 22:02:43 +03:00
parent 36810dc5f1
commit 81654c0d33
73 changed files with 4061 additions and 820 deletions
@@ -39,7 +39,14 @@ internal sealed class CreateEmailTemplateHandler
Variables = request.Variables
};
await _templates.AddAsync(template, cancellationToken);
try
{
await _templates.AddAsync(template, cancellationToken);
}
catch (EmailTemplateWriteException error)
{
return Failure<Guid>(error.Message, error.IsConflict ? ServiceErrorCode.Conflict : ServiceErrorCode.InvalidRequest);
}
return Success(template.Id);
}
@@ -7,5 +7,6 @@ namespace HrynCo.NotificationService.Services.EmailTemplates.Delete;
public sealed record DeleteEmailTemplateCommand(
string ServiceName,
string Key,
string LanguageCode
string LanguageCode,
Guid? ExpectedVersionId = null
) : IRequest<ServiceResult<Unit>>;
@@ -1,3 +1,4 @@
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -27,8 +28,17 @@ internal sealed class DeleteEmailTemplateHandler
if (template is null)
return Failure<Unit>("Template not found.", ServiceErrorCode.NotFound);
if (request.ExpectedVersionId is Guid expectedId && template.Id != expectedId)
return Failure<Unit>("Template changed after you opened it. Reload before deleting.", ServiceErrorCode.Conflict);
await _templates.DeleteAsync(template, cancellationToken);
try
{
await _templates.DeleteAsync(template, cancellationToken);
}
catch (EmailTemplateWriteException error)
{
return Failure<Unit>(error.Message, error.IsConflict ? ServiceErrorCode.Conflict : ServiceErrorCode.InvalidRequest);
}
return Success(Unit.Value);
}
@@ -0,0 +1,8 @@
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.NotificationService.Services.Core;
using MediatR;
namespace HrynCo.NotificationService.Services.EmailTemplates.SaveDefinition;
public sealed record SaveEmailTemplateDefinitionCommand(EmailTemplateDefinition Definition, bool IsNew)
: IRequest<ServiceResult<Guid>>;
@@ -0,0 +1,26 @@
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.SaveDefinition;
internal sealed class SaveEmailTemplateDefinitionHandler(
IContextualSerilogLogger<SaveEmailTemplateDefinitionCommand> logger,
IEmailTemplateDefinitionRepository definitions)
: RequestHandler<SaveEmailTemplateDefinitionCommand, ServiceResult<Guid>>(logger)
{
protected override async Task<ServiceResult<Guid>> DoOnHandle(SaveEmailTemplateDefinitionCommand request, CancellationToken cancellationToken)
{
try
{
await definitions.SaveDefinitionAsync(request.Definition, request.IsNew, cancellationToken);
return Success(request.Definition.Id);
}
catch (EmailTemplateWriteException error)
{
return Failure<Guid>(error.Message, error.IsConflict ? ServiceErrorCode.Conflict : ServiceErrorCode.InvalidRequest);
}
}
}
@@ -1,3 +1,4 @@
using HrynCo.NotificationService.DAL.Abstract.Templates;
using HrynCo.DAL.Abstract;
using HrynCo.NotificationService.DAL.Abstract.Repositories;
using HrynCo.NotificationService.Services.Core;
@@ -34,7 +35,14 @@ internal sealed class UpdateEmailTemplateHandler
template.Variables = request.Variables;
template.Updated = DateTimeOffset.UtcNow;
await _templates.UpdateAsync(template, cancellationToken);
try
{
await _templates.UpdateAsync(template, cancellationToken);
}
catch (EmailTemplateWriteException error)
{
return Failure<Unit>(error.Message, error.IsConflict ? ServiceErrorCode.Conflict : ServiceErrorCode.InvalidRequest);
}
return Success(Unit.Value);
}