517b38791b
Add revision-protected reads, atomic upsert and deletion with structured actions. Preserve omitted translations and fix insertion of new push languages. Ref: IT-1627
28 lines
1.4 KiB
C#
28 lines
1.4 KiB
C#
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.TemplateDefinitions;
|
|
|
|
internal sealed class UpsertPushTemplateDefinitionHandler(
|
|
IContextualSerilogLogger<UpsertPushTemplateDefinitionCommand> logger, IPushTemplateDefinitionRepository definitions)
|
|
: RequestHandler<UpsertPushTemplateDefinitionCommand, ServiceResult<PushTemplateDefinitionDto>>(logger)
|
|
{
|
|
protected override async Task<ServiceResult<PushTemplateDefinitionDto>> DoOnHandle(UpsertPushTemplateDefinitionCommand request, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
var definition = await definitions.UpsertDefinitionAsync(request.Patch, cancellationToken);
|
|
return definition is null
|
|
? Failure<PushTemplateDefinitionDto>("Service not found.", ServiceErrorCode.NotFound)
|
|
: Success(PushTemplateDefinitionMapping.Map(definition));
|
|
}
|
|
catch (EmailTemplateWriteException error)
|
|
{
|
|
return Failure<PushTemplateDefinitionDto>(error.Message, error.IsConflict ? ServiceErrorCode.Conflict : ServiceErrorCode.InvalidRequest);
|
|
}
|
|
}
|
|
}
|