Refactor email template commands and controller logic
- Updated namespace for `ResetEmailTemplateCommand` and added a constructor for flexible initialization. - Introduced `ChangedWhen` property in `UpdateEmailTemplateCommand` to track modification time. - Refactored `UpdateEmailTemplateCommandHandler` for improved email template retrieval logic. - Modified `EmailTemplateController` method signatures and logic for clarity and consistency. - Added `EmailTemplate` entry in `appsettings.json` for database trigger configuration.
This commit is contained in:
parent
83fa5a29e8
commit
8b4ad5e28d
@ -7,8 +7,7 @@ namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset;
|
|||||||
/// Ein Befehl zum Zurücksetzen einer E-Mail-Vorlage auf die Standardwerte.
|
/// Ein Befehl zum Zurücksetzen einer E-Mail-Vorlage auf die Standardwerte.
|
||||||
/// Erbt von <see cref="EmailTemplateQuery"/> und ermöglicht die Angabe einer optionalen ID und eines Typs der E-Mail-Vorlage.
|
/// Erbt von <see cref="EmailTemplateQuery"/> und ermöglicht die Angabe einer optionalen ID und eines Typs der E-Mail-Vorlage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="Id">Die optionale ID der E-Mail-Vorlage, die zurückgesetzt werden soll.</param>
|
/// Beispiele:
|
||||||
/// <param name="Type">Der Typ der E-Mail-Vorlage, z. B. <see cref="Constants.EmailTemplateType"/> (optional). Beispiele:
|
|
||||||
/// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.
|
/// 0 - DocumentReceived: Benachrichtigung über den Empfang eines Dokuments.
|
||||||
/// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.
|
/// 1 - DocumentSigned: Benachrichtigung über die Unterzeichnung eines Dokuments.
|
||||||
/// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.
|
/// 2 - DocumentDeleted: Benachrichtigung über das Löschen eines Dokuments.
|
||||||
@ -20,4 +19,23 @@ namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset;
|
|||||||
/// 8 - DocumentRejected_REC (Für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.
|
/// 8 - DocumentRejected_REC (Für den ablehnenden Empfänger): Mail an den ablehnenden Empfänger, wenn das Dokument abgelehnt wird.
|
||||||
/// 9 - DocumentRejected_REC_2 (Für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.
|
/// 9 - DocumentRejected_REC_2 (Für sonstige Empfänger): Mail an andere Empfänger (Brief), wenn das Dokument abgelehnt wird.
|
||||||
/// </param>
|
/// </param>
|
||||||
public record ResetEmailTemplateCommand(int? Id = null, Constants.EmailTemplateType? Type = null) : EmailTemplateQuery(Id, Type), IRequest;
|
public record ResetEmailTemplateCommand : EmailTemplateQuery, IRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="orginal"></param>
|
||||||
|
public ResetEmailTemplateCommand(EmailTemplateQuery? orginal = null) : base(orginal ?? new())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id">Die optionale ID der E-Mail-Vorlage, die zurückgesetzt werden soll.</param>
|
||||||
|
/// <param name="Type">Der Typ der E-Mail-Vorlage, z. B. <see cref="Constants.EmailTemplateType"/> (optional).
|
||||||
|
public ResetEmailTemplateCommand(int? Id = null, Constants.EmailTemplateType? Type = null) : base(Id, Type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@ -20,4 +20,10 @@ public record UpdateEmailTemplateCommand(string? Body = null, string? Subject =
|
|||||||
/// </param>
|
/// </param>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public EmailTemplateQuery? EmailTemplateQuery { get; set; }
|
public EmailTemplateQuery? EmailTemplateQuery { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime ChangedWhen { get; init; } = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,13 +34,27 @@ public class UpdateEmailTemplateCommandHandler : IRequestHandler<UpdateEmailTemp
|
|||||||
/// <exception cref="NotFoundException"></exception>
|
/// <exception cref="NotFoundException"></exception>
|
||||||
public async Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel)
|
public async Task Handle(UpdateEmailTemplateCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var temp = (request.EmailTemplateQuery?.Id is int id
|
EmailTemplateDto? temp;
|
||||||
? await _repository.ReadOrDefaultAsync<EmailTemplateDto>(t => t.Id == id, single: false, cancel)
|
|
||||||
: request!.EmailTemplateQuery!.Type is Common.Constants.EmailTemplateType type
|
|
||||||
? await _repository.ReadOrDefaultAsync<EmailTemplateDto>(t => t.Name == type.ToString(), single: false, cancel)
|
|
||||||
: throw new InvalidOperationException("Both id and type is null. Id: " + request.EmailTemplateQuery.Id + ". Type: " + request.EmailTemplateQuery.Type.ToString())) ?? throw new NotFoundException();
|
|
||||||
|
|
||||||
if(request.Body is not null)
|
if (request.EmailTemplateQuery?.Id is int id)
|
||||||
|
{
|
||||||
|
temp = await _repository.ReadOrDefaultAsync<EmailTemplateDto>(t => t.Id == id, single: false, cancel);
|
||||||
|
}
|
||||||
|
else if (request!.EmailTemplateQuery!.Type is Common.Constants.EmailTemplateType type)
|
||||||
|
{
|
||||||
|
temp = await _repository.ReadOrDefaultAsync<EmailTemplateDto>(t => t.Name == type.ToString(), single: false, cancel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Both id and type is null. Id: " + request.EmailTemplateQuery.Id +". Type: " + request.EmailTemplateQuery.Type.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.Body is not null)
|
||||||
temp.Body = request.Body;
|
temp.Body = request.Body;
|
||||||
|
|
||||||
if (request.Subject is not null)
|
if (request.Subject is not null)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ using EnvelopeGenerator.Application.Exceptions;
|
|||||||
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
|
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controller for managing email templates.
|
/// Controller for managing temp templates.
|
||||||
/// Steuerung zur Verwaltung von E-Mail-Vorlagen.
|
/// Steuerung zur Verwaltung von E-Mail-Vorlagen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
@ -84,10 +84,10 @@ public class EmailTemplateController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates an email template or resets it if no update command is provided.
|
/// Updates an temp template or resets it if no update command is provided.
|
||||||
/// Aktualisiert eine E-Mail-Vorlage oder setzt sie zurück, wenn kein Aktualisierungsbefehl angegeben ist.
|
/// Aktualisiert eine E-Mail-Vorlage oder setzt sie zurück, wenn kein Aktualisierungsbefehl angegeben ist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="email">Die E-Mail-Vorlagenabfrage.</param>
|
/// <param name="temp">Die E-Mail-Vorlagenabfrage.</param>
|
||||||
/// <param name="update">Der Aktualisierungsbefehl für die E-Mail-Vorlage.
|
/// <param name="update">Der Aktualisierungsbefehl für die E-Mail-Vorlage.
|
||||||
/// Wird auf Standardwert aktualisiert, wenn die Anfrage ohne http-Body gesendet wird.
|
/// Wird auf Standardwert aktualisiert, wenn die Anfrage ohne http-Body gesendet wird.
|
||||||
/// </param>
|
/// </param>
|
||||||
@ -105,19 +105,22 @@ public class EmailTemplateController : ControllerBase
|
|||||||
/// <response code="401">Wenn der Benutzer nicht authentifiziert ist.</response>
|
/// <response code="401">Wenn der Benutzer nicht authentifiziert ist.</response>
|
||||||
/// <response code="404">Wenn die gesuchte Abfrage nicht gefunden wird.</response>
|
/// <response code="404">Wenn die gesuchte Abfrage nicht gefunden wird.</response>
|
||||||
[HttpPut]
|
[HttpPut]
|
||||||
public async Task<IActionResult> Update([FromQuery] EmailTemplateQuery email, [FromBody] UpdateEmailTemplateCommand? update = null)
|
public async Task<IActionResult> Update([FromQuery] EmailTemplateQuery? temp = null, [FromBody] UpdateEmailTemplateCommand? update = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (update is null)
|
if (update is null)
|
||||||
{
|
{
|
||||||
var reset = _mapper.Map<ResetEmailTemplateCommand>(email);
|
await _mediator.Send(new ResetEmailTemplateCommand(temp));
|
||||||
await _mediator.Send(new ResetEmailTemplateCommand(email?.Id, email?.Type));
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
else if(temp is null)
|
||||||
|
{
|
||||||
|
return BadRequest("No both id and type");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var reset = _mapper.Map<ResetEmailTemplateCommand>(email);
|
update.EmailTemplateQuery = temp;
|
||||||
await _mediator.Send(update);
|
await _mediator.Send(update);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -169,7 +169,8 @@
|
|||||||
"EnvelopeHistory": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
|
"EnvelopeHistory": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
|
||||||
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
|
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
|
||||||
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
||||||
"Receiver": []
|
"Receiver": [],
|
||||||
|
"EmailTemplate": [ "TBSIG_EMAIL_TEMPLATE_AFT_UPD" ]
|
||||||
},
|
},
|
||||||
"MainPageTitle": null,
|
"MainPageTitle": null,
|
||||||
"AnnotationParams": {
|
"AnnotationParams": {
|
||||||
|
|||||||
@ -147,7 +147,8 @@
|
|||||||
"EnvelopeHistory": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
|
"EnvelopeHistory": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
|
||||||
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
|
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
|
||||||
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
|
||||||
"Receiver": []
|
"Receiver": [],
|
||||||
|
"EmailTemplate": [ "TBSIG_EMAIL_TEMPLATE_AFT_UPD" ]
|
||||||
},
|
},
|
||||||
"MainPageTitle": null,
|
"MainPageTitle": null,
|
||||||
"AnnotationParams": {
|
"AnnotationParams": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user