Refactor email template commands and add controller

- Updated `UpdateEmailTemplateCommand` to use a property for `EmailTemplateQuery` with `JsonIgnore`, allowing optional body and subject parameters.
- Simplified `UpdateToDefaultCommand` by removing documentation comments and constructor parameters.
- Corrected namespace for `ReadEmailTemplateQuery` from `Query.Read` to `Queries.Read`.
- Introduced `ResetEnvelopeTemplateCommand` with optional ID and type, inheriting from `EmailTemplateQuery`, along with detailed XML documentation.
- Added `EmailTemplateController` to manage email templates, including methods for retrieval and updates, utilizing AutoMapper and authorization attributes.
This commit is contained in:
Developer 02
2025-04-12 01:20:04 +02:00
parent f17820e011
commit fe252b9979
4 changed files with 105 additions and 8 deletions

View File

@@ -1,4 +1,6 @@
namespace EnvelopeGenerator.Application.EmailTemplates.Commands.UpdateToDefault;
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Reset;
/// <summary>
/// Ein Befehl zum Zurücksetzen einer E-Mail-Vorlage auf die Standardwerte.
@@ -17,4 +19,4 @@
/// 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.
/// </param>
public record UpdateToDefaultCommand(int? Id, Common.Constants.EmailTemplateType? Type) : EmailTemplateQuery(Id, Type);
public record ResetEnvelopeTemplateCommand(int? Id, Constants.EmailTemplateType? Type) : EmailTemplateQuery(Id, Type);

View File

@@ -1,18 +1,22 @@
namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Update;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.EmailTemplates.Commands.Update;
/// <summary>
/// Befehl zum Aktualisieren einer E-Mail-Vorlage.
/// </summary>
/// <param name="EmailTemplate">
/// Die Abfrage, die die E-Mail-Vorlage darstellt, die aktualisiert werden soll.
/// </param>
/// <param name="Body">
/// (Optional)Der neue Inhalt des E-Mail-Textkörpers. Wenn null, bleibt der vorhandene Inhalt unverändert.
/// </param>
/// <param name="Subject">
/// (Optional) Der neue Betreff der E-Mail. Wenn null, bleibt der vorhandene Betreff unverändert.
/// </param>
public record UpdateEmailTemplateCommand(EmailTemplateQuery EmailTemplate, string? Body = null, string? Subject = null)
public record UpdateEmailTemplateCommand(string? Body = null, string? Subject = null)
{
/// <param>
/// Die Abfrage, die die E-Mail-Vorlage darstellt, die aktualisiert werden soll.
/// </param>
[JsonIgnore]
public EmailTemplateQuery? EmailTemplateQuery { get; set; }
}

View File

@@ -1,4 +1,4 @@
namespace EnvelopeGenerator.Application.EmailTemplates.Query.Read;
namespace EnvelopeGenerator.Application.EmailTemplates.Queries.Read;
/// <summary>

View File

@@ -0,0 +1,91 @@
using AutoMapper;
using EnvelopeGenerator.Application.EmailTemplates;
using EnvelopeGenerator.Application.EmailTemplates.Commands.Update;
using EnvelopeGenerator.Application.EmailTemplates.Commands.Reset;
using EnvelopeGenerator.Application.EmailTemplates.Queries.Read;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
/// <summary>
/// Controller for managing email templates.
/// Steuerung zur Verwaltung von E-Mail-Vorlagen.
/// </summary>
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class EmailTemplateController : ControllerBase
{
private readonly IMapper _mapper;
/// <summary>
/// Initialisiert eine neue Instanz der <see cref="EmailTemplateController"/>-Klasse.
/// </summary>
/// <param name="mapper">
/// Die AutoMapper-Instanz, die zum Zuordnen von Objekten verwendet wird.
/// </param>
public EmailTemplateController(IMapper mapper)
{
_mapper = mapper;
}
/// <summary>
/// Ruft E-Mail-Vorlagen basierend auf der angegebenen Abfrage ab.
/// Gibt alles zurück, wenn keine Id- oder Typ-Informationen eingegeben wurden.
/// </summary>
/// <param name="emailTemplate">Die Abfrageparameter zum Abrufen von E-Mail-Vorlagen.</param>
/// <returns>Gibt HTTP-Antwort zurück</returns>
/// <remarks>
/// Sample request:
/// GET /api/EmailTemplate?emailTemplateId=123
/// </remarks>
/// <response code="200">Wenn die E-Mail-Vorlagen erfolgreich abgerufen werden.</response>
/// <response code="400">Wenn die Abfrageparameter ungültig sind.</response>
/// <response code="401">Wenn der Benutzer nicht authentifiziert ist.</response>
/// <response code="404">Wenn die gesuchte Abfrage nicht gefunden wird.</response>
[HttpGet]
public IActionResult Get([FromQuery] ReadEmailTemplateQuery? emailTemplate = null)
{
// Implementation logic here
return Ok(); // Placeholder for actual implementation
}
/// <summary>
/// Updates an email 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="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>
/// <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 IActionResult Update([FromQuery] EmailTemplateQuery email, [FromBody] UpdateEmailTemplateCommand? update = null)
{
if (update is null)
{
var reset = _mapper.Map<ResetEnvelopeTemplateCommand>(email);
// Logic for resetting the email template
}
else
{
update.EmailTemplateQuery = email;
// Logic for updating the email template
}
return Ok(); // Placeholder for actual implementation
}
}