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:
Developer 02
2025-05-08 17:47:18 +02:00
parent 83fa5a29e8
commit 8b4ad5e28d
6 changed files with 61 additions and 18 deletions

View File

@@ -15,7 +15,7 @@ using EnvelopeGenerator.Application.Exceptions;
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
/// <summary>
/// Controller for managing email templates.
/// Controller for managing temp templates.
/// Steuerung zur Verwaltung von E-Mail-Vorlagen.
/// </summary>
[Route("api/[controller]")]
@@ -84,10 +84,10 @@ public class EmailTemplateController : ControllerBase
}
/// <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.
/// </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.
/// Wird auf Standardwert aktualisiert, wenn die Anfrage ohne http-Body gesendet wird.
/// </param>
@@ -105,19 +105,22 @@ public class EmailTemplateController : ControllerBase
/// <response code="401">Wenn der Benutzer nicht authentifiziert ist.</response>
/// <response code="404">Wenn die gesuchte Abfrage nicht gefunden wird.</response>
[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
{
if (update is null)
{
var reset = _mapper.Map<ResetEmailTemplateCommand>(email);
await _mediator.Send(new ResetEmailTemplateCommand(email?.Id, email?.Type));
await _mediator.Send(new ResetEmailTemplateCommand(temp));
return Ok();
}
else if(temp is null)
{
return BadRequest("No both id and type");
}
else
{
var reset = _mapper.Map<ResetEmailTemplateCommand>(email);
update.EmailTemplateQuery = temp;
await _mediator.Send(update);
return Ok();
}

View File

@@ -169,7 +169,8 @@
"EnvelopeHistory": [ "TBSIG_ENVELOPE_HISTORY_AFT_INS" ],
"EmailOut": [ "TBEMLP_EMAIL_OUT_AFT_INS", "TBEMLP_EMAIL_OUT_AFT_UPD" ],
"EnvelopeReceiverReadOnly": [ "TBSIG_ENVELOPE_RECEIVER_READ_ONLY_UPD" ],
"Receiver": []
"Receiver": [],
"EmailTemplate": [ "TBSIG_EMAIL_TEMPLATE_AFT_UPD" ]
},
"MainPageTitle": null,
"AnnotationParams": {