Refactor email template command and controller
Updated namespace for `ResetEnvelopeTemplateCommand` and added default values for constructor parameters. Enhanced `EmailTemplateController` by making the `Update` method asynchronous, adding error handling, and incorporating a `try-catch` block for improved responsiveness and error management.
This commit is contained in:
@@ -8,6 +8,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using EnvelopeGenerator.Application.Contracts.Repositories;
|
||||
using EnvelopeGenerator.Application.DTOs;
|
||||
using MediatR;
|
||||
using System.Threading.Tasks;
|
||||
using DigitalData.UserManager.Application.Services;
|
||||
|
||||
namespace EnvelopeGenerator.GeneratorAPI.Controllers;
|
||||
|
||||
@@ -102,19 +104,27 @@ 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 IActionResult Update([FromQuery] EmailTemplateQuery email, [FromBody] UpdateEmailTemplateCommand? update = null)
|
||||
public async Task<IActionResult> Update([FromQuery] EmailTemplateQuery email, [FromBody] UpdateEmailTemplateCommand? update = null)
|
||||
{
|
||||
if (update is null)
|
||||
try
|
||||
{
|
||||
var reset = _mapper.Map<ResetEnvelopeTemplateCommand>(email);
|
||||
// Logic for resetting the email template
|
||||
}
|
||||
else
|
||||
{
|
||||
update.EmailTemplateQuery = email;
|
||||
// Logic for updating the email template
|
||||
}
|
||||
if (update is null)
|
||||
{
|
||||
var reset = _mapper.Map<ResetEnvelopeTemplateCommand>(email);
|
||||
await _mediator.Send(new ResetEnvelopeTemplateCommand(email?.Id, email?.Type));
|
||||
return Ok();
|
||||
}
|
||||
else
|
||||
{
|
||||
update.EmailTemplateQuery = email;
|
||||
// Logic for updating the email template
|
||||
}
|
||||
|
||||
return Ok(); // Placeholder for actual implementation
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "An unexpected error occurred. {message}", ex.Message);
|
||||
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user