8e81572386
Add revision-safe service and template APIs, channel mapping, and validated admin controls. Ref: IT-1601
31 lines
1.5 KiB
C#
31 lines
1.5 KiB
C#
using HrynCo.NotificationService.DAL.Abstract.Templates;
|
|
|
|
namespace HrynCo.NotificationService.Web.Controllers.Api.Services;
|
|
|
|
public sealed class UpsertTemplateDefinitionRequest
|
|
{
|
|
public Guid? Revision { get; init; }
|
|
public required IReadOnlyList<TemplateVariableRequest> Variables { get; init; }
|
|
public required IReadOnlyList<TemplateTranslationRequest> Translations { get; init; }
|
|
public IReadOnlyList<string>? RemoveLanguageCodes { get; init; }
|
|
|
|
public EmailTemplateDefinitionPatch ToPatch(Guid serviceId, string key)
|
|
{
|
|
if (Variables is null || Translations is null)
|
|
throw new EmailTemplateWriteException("variables and translations must be JSON arrays, including when empty.", false);
|
|
if (Variables.Any(v => v is null) || Translations.Any(t => t is null))
|
|
throw new EmailTemplateWriteException("variables and translations cannot contain null elements.", false);
|
|
return new EmailTemplateDefinitionPatch
|
|
{
|
|
ServiceId = serviceId, Key = key, Revision = Revision,
|
|
Variables = Variables.Select(v => new EmailTemplateVariable { Name = v.Name, Required = v.Required }).ToList(),
|
|
Translations = Translations.Select(t => new EmailTemplate
|
|
{
|
|
ServiceName = "", Key = key, LanguageCode = t.LanguageCode, Created = DateTimeOffset.UtcNow,
|
|
Subject = t.Subject, HtmlBody = t.HtmlBody, TextBody = t.TextBody
|
|
}).ToList(),
|
|
RemoveLanguageCodes = RemoveLanguageCodes ?? []
|
|
};
|
|
}
|
|
}
|