Refactor EmailTemplate Update method signature and logic

Simplified XML docs and removed sample requests. Changed Update method to require UpdateEmailTemplateCommand and CancellationToken, eliminating optional query parameter. Streamlined logic to send update command directly, removing previous conditional handling for null values and template resets.
This commit is contained in:
2026-02-11 10:24:54 +01:00
parent d31916eab8
commit c8ca1ef22a

View File

@@ -62,40 +62,17 @@ public class EmailTemplateController(IMapper mapper, IRepository<EmailTemplate>
/// 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="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>
/// <returns>Gibt HTTP-Antwort zurück</returns>
/// <remarks>
/// Sample request:
/// PUT /api/EmailTemplate
/// {
/// "emailTemplateId": 123,
/// "newContent": "Updated content"
/// }
/// </remarks>
/// <param name="update"></param>
/// <param name="cancel"></param>
/// <returns></returns>
/// <response code="200">Wenn die E-Mail-Vorlage erfolgreich aktualisiert oder zurückgesetzt wird.</response>
/// <response code="400">Wenn die Abfrage ohne einen String gesendet wird.</response>
/// <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] IEmailTemplateQuery? temp = null, [FromBody] UpdateEmailTemplateCommand? update = null)
public async Task<IActionResult> Update([FromBody] UpdateEmailTemplateCommand update, CancellationToken cancel)
{
if (update is null)
{
await mediator.Send(new ResetEmailTemplateCommand(temp));
return Ok();
}
else if (temp is null)
{
return BadRequest("No both id and type");
}
else
{
update.EmailTemplateQuery = temp;
await mediator.Send(update);
return Ok();
}
await mediator.Send(update, cancel);
return Ok();
}
}