From d094fe14da379069a5f216244183ae59fef4cdd6 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 9 Feb 2026 11:39:16 +0100 Subject: [PATCH] Refactor UpdateEmailTemplateCommand to use base classes Refactored UpdateEmailTemplateCommand and its handler to inherit from generic UpdateCommand and UpdateCommandHandler base classes. Replaced QueryExpression with BuildQueryExpression(), removed redundant Update property, and cleaned up unused usings. This improves code reuse, modularity, and consistency across update commands. --- .../Commands/UpdateEmailTemplateCommand.cs | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs index 25ed293e..71421a68 100644 --- a/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs +++ b/EnvelopeGenerator.Application/EmailTemplates/Commands/UpdateEmailTemplateCommand.cs @@ -1,9 +1,7 @@ -using AutoMapper; -using DigitalData.Core.Abstraction.Application.Repository; -using DigitalData.Core.Exceptions; +using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Common.Commands; using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Entities; -using MediatR; using System.Linq.Expressions; namespace EnvelopeGenerator.Application.EmailTemplates.Commands; @@ -18,7 +16,7 @@ public record EmailTemplateUpdateDto(string Body, string Subject); /// /// Befehl zum Aktualisieren einer E-Mail-Vorlage. /// -public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest +public record UpdateEmailTemplateCommand : UpdateCommand, IEmailTemplateQuery { /// /// Die eindeutige Kennung der E-Mail-Vorlage (optional). @@ -43,40 +41,23 @@ public record UpdateEmailTemplateCommand : IEmailTemplateQuery, IRequest /// /// /// - public Expression> QueryExpression => Id is int id + /// + public override Expression> BuildQueryExpression() + => Id is int id ? temp => temp.Id == id : temp => temp!.Name == Type.ToString(); - - /// - /// Die aktualisierte E-Mail-Vorlage. - /// - public EmailTemplateUpdateDto Update { get; init; } = null!; } /// /// /// -public class UpdateEmailTemplateCommandHandler : IRequestHandler +public class UpdateEmailTemplateCommandHandler : UpdateCommandHandler { - private readonly IRepository _repository; - /// /// /// /// - public UpdateEmailTemplateCommandHandler(IRepository repository) + public UpdateEmailTemplateCommandHandler(IRepository repository) : base(repository) { - _repository = repository; } - - /// - /// - /// - /// - /// - /// - /// - /// - public Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel) - => _repository.UpdateAsync(request.Update, request.QueryExpression, cancel); } \ No newline at end of file